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.
我正在使用MSBuild(通过NAnt)来编译一堆VB.NET程序集。因为这些程序集依赖于COM Interop,所以我需要保证它们在64位OS上以32位模式运行。我可以通过在Visual Studio中更改项目来将可执行程序集编译为32位,但我真的希望能够在构建服务器上强制将所有可执行文件编译为32位模式。
I've tried a number of command-line parameters to MSBuild with no luck:
我已经尝试了许多命令行参数到MSBuild没有运气:
- /p:Platform=win32
- / P:平台= win32的
- /p:Platform=x86
- / P:平台= 86
- /p:ProcessorArchitecture=x86
- / P:ProcessorArchitecture用于= 86
What am I doing wrong? Is there some reference to the properties that MSBuild uses when compiling VB projects?
我究竟做错了什么?是否有一些参考MSBuild在编译VB项目时使用的属性?
8 个解决方案
#1
19
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.
如果程序集本身总是32位,为什么不将设置添加到.vbproj文件?这将使MSBuild脱离等式。
Just add the following line to the initial PropertyGroup in the .vbproj file
只需将以下行添加到.vbproj文件中的初始PropertyGroup即可
<PlatformTarget>x86</PlatformTarget>
#2
45
According to MSDN, you're doing the right thing. Looks like /p:Platform=x86
, but actually, maybe it's /p:PlatformTarget=x86
.
根据MSDN,你做的是正确的。看起来像/ p:Platform = x86,但实际上,也许它是/ 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).
尝试直接使用该参数调用MSBuild(确保它不是您的NAnt文件的问题。查看正确的构建配置(调试/发布)的构建输出。
#3
12
Just in case this helps, I used this commandline to build my x86 platform target:
为了防止这种情况,我使用这个命令行来构建我的x86平台目标:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe my.sln /t:build /p:Configuration=Release;Platform=x86
#4
3
In Solution Explorer, right click the root node -> Configuration Manager. You need to define a solution-wide configuration that instructs each project within to build as 32-bit. (Note: you probably already have one if you've ever set at least one project to build as 32-bit.) For a step-by-step walkthrough, see the MSDN blog post Solution Configurations.
在解决方案资源管理器中,右键单击根节点 - >配置管理器。您需要定义一个解决方案范围的配置,指示每个项目内部构建为32位。 (注意:如果您已经将至少一个项目设置为32位,则可能已经有一个。)有关分步演练,请参阅MSDN博客文章解决方案配置。
Then, you specify the desired "platform" and "flavor" in your Team Build .proj
/ .targets
files. For example:
然后,在Team Build .proj / .targets文件中指定所需的“平台”和“风味”。例如:
<ConfigurationToBuild Include="Release|x86">
<FlavorToBuild>Release</FlavorToBuild>
<PlatformToBuild>x86</PlatformToBuild>
</ConfigurationToBuild>
You can specify more than one of these property sections to have several combinations built. I would copy/paste the "Release|x86" string (or whatever it looks like) directly from your .sln
file to ensure it matches exactly -- you can't get it directly from Solution Explorer.
您可以指定多个属性部分以构建多个组合。我会直接从你的.sln文件中复制/粘贴“Release | x86”字符串(或者它看起来像什么)以确保它完全匹配 - 你无法直接从Solution Explorer中获取它。
Regarding your comment:
关于你的评论:
MSBuild property evaluation is pretty complex since it mixes declarative and imperative styles. See the blog post MSBuild Property Evaluation for details. I prefer not to rely on its subtleties.
MSBuild属性评估非常复杂,因为它混合了声明式和命令式样式。有关详细信息,请参阅博客文章MSBuild Property Evaluation。我宁愿不依赖它的微妙之处。
It's true that properties specified on the command line should override everything else, but Team Build has another layer of complexity. The ComputeConfigurationList task is called repeatedly via a recursive MSBuild invokation, not as an ordinary task. The way it pulls this off is to take the ordinary properties like PlatformToBuild
and wrap them in a set of global properties called ConfigurationToBuild.PlatformToBuild
(etc.) which are generated on the fly, once for each configuration. This makes the Team Build engine much more flexible internally, but it also makes hacking the command line behavior you want harder.
确实,在命令行上指定的属性应该覆盖其他所有属性,但Team Build具有另一层复杂性。通过递归MSBuild调用重复调用ComputeConfigurationList任务,而不是普通任务。解决这个问题的方法是采用像PlatformToBuild这样的普通属性,并将它们包装在一组名为ConfigurationToBuild.PlatformToBuild(等)的全局属性中,这些属性是动态生成的,每次配置一次。这使得Team Build引擎在内部变得更加灵活,但它也会使你想要的命令行行为变得更加困难。
You could try setting ConfigurationToBuild.PlatformToBuild
on the command line directly -- it might work, I'm not sure. But it will definitely prevent you from ever building more than one configuration in a single build definition. For this reason, I'm sticking with my advice above.
您可以尝试直接在命令行上设置ConfigurationToBuild.PlatformToBuild - 它可能会起作用,我不确定。但它肯定会阻止您在单个构建定义中构建多个配置。出于这个原因,我坚持上面的建议。
#5
2
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.
在遇到完全相同的问题之后,我从使用C:\ WINDOWS \ Microsoft.NET \ Framework64的MSBuild版本切换到C:\ WINDOWS \ Microsoft.NET \ Framework(没有64)的版本和编译的东西正好。
#6
1
The Nant msbuild-Task answer to this question:
Nant msbuild-Task回答了这个问题:
<msbuild project="your.sln">
<property name="PlatformTarget" value="x86" />
</msbuild>
#7
1
For MSBuild version 15 it is /p:PlatformTarget=x86
对于MSBuild版本15,它是/ p:PlatformTarget = x86
#8
0
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.
我用来找到正确属性的一种更实用的方法是打开一个.csproj项目文件(如果是c#),并从Visual中选择“x64”/“AnyCPU”/“x86”时看到受影响的属性STDIO。无论更改哪个属性,您都需要从命令行设置它。使用Visual Studio 2015,它似乎是
#1
19
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.
如果程序集本身总是32位,为什么不将设置添加到.vbproj文件?这将使MSBuild脱离等式。
Just add the following line to the initial PropertyGroup in the .vbproj file
只需将以下行添加到.vbproj文件中的初始PropertyGroup即可
<PlatformTarget>x86</PlatformTarget>
#2
45
According to MSDN, you're doing the right thing. Looks like /p:Platform=x86
, but actually, maybe it's /p:PlatformTarget=x86
.
根据MSDN,你做的是正确的。看起来像/ p:Platform = x86,但实际上,也许它是/ 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).
尝试直接使用该参数调用MSBuild(确保它不是您的NAnt文件的问题。查看正确的构建配置(调试/发布)的构建输出。
#3
12
Just in case this helps, I used this commandline to build my x86 platform target:
为了防止这种情况,我使用这个命令行来构建我的x86平台目标:
C:\Windows\Microsoft.NET\Framework\v2.0.50727\MSBuild.exe my.sln /t:build /p:Configuration=Release;Platform=x86
#4
3
In Solution Explorer, right click the root node -> Configuration Manager. You need to define a solution-wide configuration that instructs each project within to build as 32-bit. (Note: you probably already have one if you've ever set at least one project to build as 32-bit.) For a step-by-step walkthrough, see the MSDN blog post Solution Configurations.
在解决方案资源管理器中,右键单击根节点 - >配置管理器。您需要定义一个解决方案范围的配置,指示每个项目内部构建为32位。 (注意:如果您已经将至少一个项目设置为32位,则可能已经有一个。)有关分步演练,请参阅MSDN博客文章解决方案配置。
Then, you specify the desired "platform" and "flavor" in your Team Build .proj
/ .targets
files. For example:
然后,在Team Build .proj / .targets文件中指定所需的“平台”和“风味”。例如:
<ConfigurationToBuild Include="Release|x86">
<FlavorToBuild>Release</FlavorToBuild>
<PlatformToBuild>x86</PlatformToBuild>
</ConfigurationToBuild>
You can specify more than one of these property sections to have several combinations built. I would copy/paste the "Release|x86" string (or whatever it looks like) directly from your .sln
file to ensure it matches exactly -- you can't get it directly from Solution Explorer.
您可以指定多个属性部分以构建多个组合。我会直接从你的.sln文件中复制/粘贴“Release | x86”字符串(或者它看起来像什么)以确保它完全匹配 - 你无法直接从Solution Explorer中获取它。
Regarding your comment:
关于你的评论:
MSBuild property evaluation is pretty complex since it mixes declarative and imperative styles. See the blog post MSBuild Property Evaluation for details. I prefer not to rely on its subtleties.
MSBuild属性评估非常复杂,因为它混合了声明式和命令式样式。有关详细信息,请参阅博客文章MSBuild Property Evaluation。我宁愿不依赖它的微妙之处。
It's true that properties specified on the command line should override everything else, but Team Build has another layer of complexity. The ComputeConfigurationList task is called repeatedly via a recursive MSBuild invokation, not as an ordinary task. The way it pulls this off is to take the ordinary properties like PlatformToBuild
and wrap them in a set of global properties called ConfigurationToBuild.PlatformToBuild
(etc.) which are generated on the fly, once for each configuration. This makes the Team Build engine much more flexible internally, but it also makes hacking the command line behavior you want harder.
确实,在命令行上指定的属性应该覆盖其他所有属性,但Team Build具有另一层复杂性。通过递归MSBuild调用重复调用ComputeConfigurationList任务,而不是普通任务。解决这个问题的方法是采用像PlatformToBuild这样的普通属性,并将它们包装在一组名为ConfigurationToBuild.PlatformToBuild(等)的全局属性中,这些属性是动态生成的,每次配置一次。这使得Team Build引擎在内部变得更加灵活,但它也会使你想要的命令行行为变得更加困难。
You could try setting ConfigurationToBuild.PlatformToBuild
on the command line directly -- it might work, I'm not sure. But it will definitely prevent you from ever building more than one configuration in a single build definition. For this reason, I'm sticking with my advice above.
您可以尝试直接在命令行上设置ConfigurationToBuild.PlatformToBuild - 它可能会起作用,我不确定。但它肯定会阻止您在单个构建定义中构建多个配置。出于这个原因,我坚持上面的建议。
#5
2
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.
在遇到完全相同的问题之后,我从使用C:\ WINDOWS \ Microsoft.NET \ Framework64的MSBuild版本切换到C:\ WINDOWS \ Microsoft.NET \ Framework(没有64)的版本和编译的东西正好。
#6
1
The Nant msbuild-Task answer to this question:
Nant msbuild-Task回答了这个问题:
<msbuild project="your.sln">
<property name="PlatformTarget" value="x86" />
</msbuild>
#7
1
For MSBuild version 15 it is /p:PlatformTarget=x86
对于MSBuild版本15,它是/ p:PlatformTarget = x86
#8
0
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.
我用来找到正确属性的一种更实用的方法是打开一个.csproj项目文件(如果是c#),并从Visual中选择“x64”/“AnyCPU”/“x86”时看到受影响的属性STDIO。无论更改哪个属性,您都需要从命令行设置它。使用Visual Studio 2015,它似乎是