Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

building x64 c# project with msbuild results in 32bit targets

Tags:

msbuild

I'm using Visual Studio 2010 to build a c# project that has both x86 and x64 targets. When I build using the IDE, I get the correct result of x64 and x86 targets.

When I use msbuild on the command line, I get everything built in x86, even though i specify x64 on the command line.

I didn't have this problem until I upgraded from .Net 4.0 to .Net 4.5.

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

I did a build in the .Net 4.0 environment and then another build in the .Net 4.5 environment and piped the output into log files. I noticed some differences in the log files but I think this is what is causing my issue:

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 is using an x86 specific path.

like image 305
Tony Avatar asked Apr 01 '13 15:04

Tony


People also ask

Do I need x86 or x64 C++?

In most cases you should install both the x64 (64-bit) and the x86 (32-bit) versions. If you're using a 32-bit version of Windows, then you only need to install the x86 version.

How do I change from x86 to x64 in Visual Studio?

From the BUILD menu in Visual Studio, select Configuration Manager. From the Active solution platform drop-down list, select New. The New Solution Platform dialog displays. In the Type or select new platform combination box, select x64.

Is there a built in C compiler in Windows?

Unfortunately, there is no in-built compiler. You need to install one.

Can you develop C in Visual Studio?

The Microsoft C/C++ for Visual Studio Code extension supports IntelliSense, debugging, code formatting, auto-completion. Visual Studio for Mac doesn't support Microsoft C++, but does support . NET languages and cross-platform development. For installation instructions, see Install Visual Studio for Mac.


1 Answers

This could happen if your solution's x64 configuration is configured to build project as AnyCPU. A new configuration option in .Net 4.5, Prefer 32 bit, makes executables with Prefer32bit flag to start up as 32-bit processes on 64 bit machine. Since Prefer32bit flag is default in MSBuild targets, you will see the behavior you describe, i.e. upgrading from .Net 4.0 to .Net 4.5 will have your AnyCPU project to switch from 64 bit to 32 bit.

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

msbuild project.csproj /p:Platform=x64

Notice, the command line is for .csproj, not for .sln.

Alternatively, verify you solution configuration in Configuration Manger and make sure it gets built as x64.

like image 146
seva titov Avatar answered Sep 22 '22 23:09

seva titov