【问题标题】:How or why is MSBuild choosing the x64 platform when I don't specify it instead of AnyCPU?当我没有指定 x64 平台而不是 AnyCPU 时,MSBuild 如何或为什么选择它?
【发布时间】:2012-02-06 08:09:01
【问题描述】:

我正在通过 Rake 从常规 PowerShell 控制台运行 msbuild.exe。这是从诊断级别运行打印的命令

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe" "D:/Projects/machine.specifications/Source/Machine.Specifications/Machine.Specifications.csproj31881140" /maxcpucount /target:构建 /verbosity:diagnostic /property:Configuration=Debug /property:TrackFileAccess=false /property:BuildInParallel=false /property:BuildRunner=Rake

构建失败是因为 msbuild 选择 x64 作为 Platform

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(483,9):错误:未为项目“Machine.Specifications.csproj37103470”设置 OutputPath 属性。请检查以确保您为此项目指定了有效的配置和平台组合。 配置='调试'平台='X64'。您可能会看到此消息,因为您正在尝试构建一个没有解决方案文件的项目,并且指定了该项目不存在的非默认配置或平台。

我没有通过命令行(或脚本)传递它。 csproj 有一个默认配置

<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

还有两个具体的配置

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">

所以,我希望选择AnyCPU 平台。但是,出于某种原因,有些东西正在x64 中挑选或发送。我认为 Rake 系统在这里不是问题,我之前在对 msbuild 的原始 cmd 行调用中看到过这种行为(但我没有记录它们)。

我在 64 位 Windows 7 上,调用 msbuild 4.0。我不知道这是否相关。


我是 loading 64 位 Visual Studio 工具 (C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64),在我的 PowerShell 配置文件中使用 Invoke-BatchFile。这会是罪魁祸首吗?

为什么msbuild会故意选择x64? 32位版本不会为你选择x86。


*1:PowerShell 控制台位于%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe *2:我正在运行MSpec 构建(这里是rakefilemsbuild call

【问题讨论】:

  • MSBuild my.sln /p:Configuration=Release /p:Platform=Any CPU 是另一种方式(来自 powershell 提示符)

标签: msbuild 64-bit


【解决方案1】:

当您启动 Visual Studio x64 命令窗口时,它会设置一个环境变量:

Platform=X64

这与 32 位命令窗口不同,后者未定义此环境变量,然后 MSBuild 使用条件逻辑使用默认平台。

您可以删除批处理文件中的 Platform 环境变量,或者将显式 Platform 属性作为参数传递给 MSBuild。

【讨论】:

  • 呃,谢谢。完全出乎意料。 MSFT 更好地理顺了他们的 x86/x64 工具故事。
  • 32 位提示不强制 x86 平台。
猜你喜欢
  • 2015-05-03
  • 2011-03-10
  • 1970-01-01
  • 2017-06-11
  • 1970-01-01
  • 2020-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多