2

Our c# project depends on some native dlls that we copy to output directory in a post-build command. We target both x86 and x64bit so we have to copy 32-bit version of native dlls for our x86 build and 64-bit versions of dlls for x64 build. We use Visual Studio 2015 and 2017

I put corresponding versions of dlls in folders "Native dlls\x86" and "Native dlls\x64". In VS2017, project properties, on project's Build Page I specify "Platform target" explicitly - either x86 or x64, not Any CPU - and I plan to use a post-build command like below

xcopy /y "$(SolutionDir)\Native dlls\ PLATFORM_x86_or_x64 \*.*" $(ProjectDir)$(OutDir)

where PLATFORM_x86_or_x64 should be a string that indicates a processor architecture the project will be built for. How can I determine in a post-build event if the compiled project will be running as a 32-bit or 64-bit process?

On Microsoft Doc I came across a PlatformShortName macro but seems it is unavailable in VS 2015/2017 - it resolves into an empty string

EDIT to explain difference between this question and Pre and Post Build event parameters:

The answers to Pre and Post Build event parameters just contain lists of pre/post-build macros that do not have a macro that specifies "Platform target" selection on project's Build Page (for VS 2015/2017)

I think that there is a confusion between two terms, chosen so similar by Microsoft:

  • "Platform Target" that defines for which CPU architecture (x86/x64 etc) the project will be compiled. Depending on this the compiled code will be running on Windows as 32bit or 64bit process and the process can load only 32bit or 64bit dlls accordingly. Platform Targets is a list with predetermined values, you cannot add a new value;
  • "Solution/Project/Build Platform" that merely is a set of build settings, that include "Platform target" itself. Microsoft also refers to it as target/targeted platform in doc. You can create your own solution platform and give it your own name. This is a developer choice what Platform target will be selected for a project's Platform, e.g. x86 Platform target can be selected for "Any CPU" project platform, or even x86 Platform target for Platform with the name "x64". Macro PlatformName determines what Solution Platform is selected.

My question was about how to determine in post-build event what Platform target selection was, or more precisely, whether the project would be compiled as a 32bit or 64bit process. Seems it is not possible to do in VS 2015/2017. I can create a post-build condition to check current solution platform (as suggested by Lex Li) and assume targeted processor architecture (Platform target) but it can be independently changed (x64 to x86, or Prefer 32-bit selected for Any CPU) and then wrong native dlls will be copied to output directory and the application will fail at runtime to load them.

Igor B
  • 98
  • 7
  • 2
    Use two post build events (one for x64, and the other for x86), and then add conditions to them to check target platform (`$(Platform) == "x86"`). – Lex Li Aug 02 '19 at 22:27
  • See marked duplicate for a list of parameters available in the build events, including the `PlatformName` parameter. – Peter Duniho Aug 04 '19 at 18:29

0 Answers0