Creating an x64 C # project with msbuild results for 32-bit purposes

I am using Visual Studio 2010 to create a C # project that has both x86 and x64 goals. When I build using the IDE, I get the correct result from x64 and x86 targets.

When I use msbuild on the command line, I get everything that was built into x86, although I specify x64 on the command line.

I did not have this problem until I upgraded from .Net 4.0 to .Net 4.5.

With .Net 4.0, I managed to get my x64 targets, even if I specified x86 on the command line.

I made a build in .Net 4.0, and then another build in .Net 4.5, and sent the output to the log files. I noticed some differences in the log files, but I think this is what causes my problem:

In .Net 4.0, I see this line in the log file:

/reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll

In .Net 4.5 I see this line in the log file: / r: "C: \ Program Files (x86) \ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.0 \ Microsoft.CSharp.dll"

Any ideas? It seams .Net 4.5 uses a specific x86 path.

+6
source share
1 answer

This can happen if your x64 configuration for configuration is configured to create a project like AnyCPU. A new configuration option in .Net 4.5, prefers 32 bits , makes executables with the Prefer32bit flag run as 32-bit processes on a 64-bit machine. Since the Prefer32bit flag is set to MSBuild by default, you will see the behavior that you are describing, i.e. upgrading from .Net 4.0 to .Net 4.5 will have an AnyCPU project to switch from 64-bit to 32-bit.

To create a project (not a solution) built for x64, specify it on the command line:

msbuild project.csproj /p:Platform=x64 

Please note: the command line is for .csproj, not .sln.

Alternatively, check the solution configuration in Configuration Manger and make sure it is built as x64.

+5
source

All Articles