How do I force MSBuild to compile for 32-bit mode?

2019-02-07 17:14发布

I'm using MSBuild (via NAnt) to compile a bunch of VB.NET assemblies. Because these assemblies depend on COM Interop, I need to guarantee that they run in 32-bit mode on 64 bit OS's. I can get the executable assemblies to compile to 32-bit by changing the project in Visual Studio, but I'd really like to be able to force all of the executables to be compiled to 32 bit mode on the build server.

I've tried a number of command-line parameters to MSBuild with no luck:

  • /p:Platform=win32
  • /p:Platform=x86
  • /p:ProcessorArchitecture=x86

What am I doing wrong? Is there some reference to the properties that MSBuild uses when compiling VB projects?

8条回答
Evening l夕情丶
2楼-- · 2019-02-07 17:47

Just in case this helps, I used this commandline to build my x86 platform target:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe my.sln /t:build /p:Configuration=Release;Platform=x86
查看更多
ゆ 、 Hurt°
3楼-- · 2019-02-07 17:53

If the assemblies themselves are always going to be 32 bit, why not add the setting to the .vbproj file? That will take MSBuild out of the equation.

Just add the following line to the initial PropertyGroup in the .vbproj file

<PlatformTarget>x86</PlatformTarget>
查看更多
【Aperson】
4楼-- · 2019-02-07 17:53

According to MSDN, you're doing the right thing. Looks like /p:Platform=x86, but actually, maybe it's /p:PlatformTarget=x86.

Try to just invoke MSBuild directly with that parameter (make sure it's not an issue with your NAnt file. Look at the build output for the right build configuration (Debug / Release).

查看更多
5楼-- · 2019-02-07 17:56

After experiencing the exact same issue, I switched from using the version of MSBuild at C:\WINDOWS\Microsoft.NET\Framework64... to the version at C:\WINDOWS\Microsoft.NET\Framework (no 64) and things compiled just fine.

查看更多
仙女界的扛把子
6楼-- · 2019-02-07 17:57

For MSBuild version 15 it is /p:PlatformTarget=x86

查看更多
趁早两清
7楼-- · 2019-02-07 18:02

A more practical way i use to find the right property is by opening one of the .csproj project file (in case of c#) and see the property that is affected when you select "x64" / "AnyCPU" / "x86" from Visual stdio. Whatever property that is changed, you need to set that from command line. With Visual studio 2015 it seems to be <Platform>. So you can invoke msbuild with the argument /p:Platform=x64 and it should work.

查看更多
登录 后发表回答