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

发布于 2024-12-25 12:58:01 字数 2262 浏览 0 评论 0原文

我通过 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 /目标:构建 /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 的原始命令行调用中见过这种行为(但我还没有记录它们)。

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


我正在加载 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 调用

I'm running msbuild.exe via Rake from a regular PowerShell console. This is the command as printed from a diagnostic level run

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

And the build is failing because msbuild is picking x64 as the Platform.

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(483,9): error : The OutputPath property is not set for project 'Machine.Specifications.csproj37103470'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='X64'. You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project.

I'm not passing it in on the command line (or from the script). The csproj has a default configuration

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

and two specific configurations

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

So, I expected the AnyCPU platform to be selected. But, for some reason, something is picking or sending in x64. I don't think the Rake system is a problem here, I've seen this behavior before on raw cmd line calls to msbuild (but I haven't documented them).

I'm on 64-bit Windows 7, calling msbuild 4.0. I don't know if that's relevant.


I am loading the 64-bit Visual Studio tools (C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64) using Invoke-BatchFile in my PowerShell profile. Could that be the culprit?

Why would msbuild deliberately choose x64 anyway? The 32-bit version doesn't choose x86 for you.


*1: The PowerShell console is at %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
*2: I'm running the MSpec build (here's the rakefile and the msbuild call)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忱杏 2025-01-01 12:58:01

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

Platform=X64

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

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

When you launch Visual Studio x64 command window, it sets an environment variable :

Platform=X64

This is a difference from the 32 bit command window, where this environment variable is not defined, and MSBuild then uses the conditional logic to use default platform.

You can either remove the Platform environment variable in your batch file, or pass in explicit Platform property as a parameter to MSBuild.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文