c++ - 如何在 MSBuild 中强制使用 C++ 平台?

标签 c++ visual-studio msbuild vcxproj

我有一个程序必须构建为 32 位。它随 x64 应用程序一起提供。结果,有一个安装程序得到了一个位数。

安装程序是用 wixproj 构建的,它必须用 /p:Platform=x64 构建——但是 vcxproj 需要构建作为 x86。

我尝试通过显式设置将 Platform 强制为 x86Win32:

<PropertyGroup>
  <Platform>Win32</Platform>
</PropertyGroup>

但似乎传递给 wixproj 的命令行开关在构建时“获胜”。

有没有什么方法可以使项目文件强制 PlatformWin32 而不管在命令行上指定了什么?

(对于 csproj 我能够做到这一点:

<PropertyGroup>
  <PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>

但这似乎对 C++ 没有任何影响)

最佳答案

终于明白了。 MSBuild 有一个设置 TreatAsLocalProperty这允许项目文件覆盖任何变量,该变量进入文件开头的 Project 节点。

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" 
         ToolsVersion="4.0"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
         TreatAsLocalProperty="Platform"> <!-- !!! -->
  <PropertyGroup>
     <Platform>Win32</Platform>
  </PropertyGroup>
  <!-- Now Platform is Win32 no matter what! -->
</Project>

关于c++ - 如何在 MSBuild 中强制使用 C++ 平台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21249108/

相关文章:

visual-studio - 在 Visual Studio 2017 或 2019 中最大化当前拆分选项卡组

c++ - golang select 语句是如何实现的?

c++ - 如何确定 Windows 驱动程序(又名内核空间)的 CPU 和内存消耗

c++ - 没有宏的模板特化类型列表?

msbuild - 错误 MSB4064 : The "OverwriteReadOnlyFiles" parameter is not supported by the "Copy" task

msbuild - VisualStudio.com 无法在构建期间加载临时 UWP 证书

c# - Windows 上的 Visual Studio Code、C# 支持

c++ - Visual Studio : Run C++ project Post-Build Event even if project is up-to-date

c# - Web.config 生产环境性能 - 最佳实践

c - 在 C (C89) 中获取指向动态库的函数指针