MSBuild 忽略所需的配置 [英] MSBuild ignores the desired configuration
问题描述
我正在尝试从命令行(通过 PowerShell 脚本)构建 Visual Studio 2019 解决方案,我需要进行 2 个构建 - 一个用于 64 位,另一个用于 32 位通过脚本.
I'm trying to build a Visual Studio 2019 solution from command line (though a PowerShell script), I need to have 2 builds - one for 64-bit and one for 32-bit though the script.
从配置管理器中,我已将 x86 和 x64 平台添加到平台:
From Configuration Manager I have added x86 and x64 platforms to the Platform:
在项目属性中,我相应地设置了平台目标:
And in the project properties I have set up the Platform target accordingly:
我正在使用以下命令行通过 MSBuild 进行构建:
I'm using the following command lines to build with MSBuild:
& $msbuildPath ../MyApp.Desktop.sln -t:Rebuild -p:Configuration=Release /p:Platform=x86
& $msbuildPath ../MyApp.Desktop.sln -t:Rebuild -p:Configuration=Release /p:Platform=x64
但它似乎忽略了 /p:Platform
因为无论我声明 x86
还是 x64
它总是构建"主动"在配置管理器中设置的平台.但是,如果我在平台中输入一个无效值(例如 x123),构建将失败,因为它不存在.
But it seems to ignore the /p:Platform
because it does not matter if I state x86
or x64
it always builds the "Active" platform set in Configuration Manager. But, if I put in platform an invalid value (for instance x123) the build would fail because that does not exist.
如何让 MSBuild 使用所述的 /p:Platform
实际构建?
How can I make MSBuild actually build with the stated /p:Platform
?
推荐答案
如果您构建 sln 文件,您应该更改解决方案平台而不是项目平台.
If you build your sln file, you should change the solution platform rather than the project platform.
请尝试以下步骤:
1)首先,删除每个项目平台,并为您的项目做一个清理.并且只保留平台Any CPU
.
1) first, delete every project platform and do a clean for your project.And only retain the platform Any CPU
.
2)为解决方案平台
3)关闭VS Instance,删除每个项目的bin
和obj
文件夹
3) close VS Instance, delete the bin
and obj
folder of every project
然后使用 /p:Platform=x64 或 x86
运行您的 powershell.它在我身边运作良好.它可以毫无问题地返回 x86
或 x64
输出文件.
then run your powershell with /p:Platform=x64 or x86
. And it works well in my side. And it can return x86
or x64
output files without any problems.
这篇关于MSBuild 忽略所需的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!