当我没有指定 x64 平台而不是 AnyCPU 时,MSBuild 如何或为何选择 x64 平台?

2024-05-10

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

“C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe”“D:/Projects/machine.specifications/Source/Machine.Specifications/Machine.Specifications.csproj31881140”/maxcpucount/target:Build/verbosity :诊断 /property:Configuration=调试 /property:TrackFileAccess=false /property:BuildInParallel=false /property:BuildRunner=Rake

并且构建失败,因为 msbuild 正在选择x64 as the 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 的原始命令行调用中见过这种行为(但我还没有记录它们)。

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


I am loading https://powershellcx.svn.codeplex.com/svn/Trunk/Src/ReleaseNotes.txt64 位 Visual Studio 工具(C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64) using Invoke-BatchFile在我的 PowerShell 配置文件中。难道这就是罪魁祸首吗?

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


*1:PowerShell 控制台位于%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe*2:我正在运行MSpec https://github.com/machine/machine.specifications构建(这是rakefile https://github.com/machine/machine.specifications/blob/master/rakefile.rbmsbuild 调用 https://github.com/machine/machine.specifications/blob/master/Tools/Rake/msbuild.rb#L40)


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

Platform=X64

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

当我没有指定 x64 平台而不是 AnyCPU 时,MSBuild 如何或为何选择 x64 平台? 的相关文章

随机推荐