gpt4 book ai didi

command-line - MSBuild.exe 不接受任一/p :DefineConstants nor/p:PreprocessorDefinitions

转载 作者:行者123 更新时间:2023-12-03 01:25:55 25 4
gpt4 key购买 nike

我在 Stack Overflow 上阅读了很多文章,这些文章回答了“如何从 MSBuild 命令行将预处理器定义传递给编译器”这一问题,它们都以以下一些变化进行了回应:

MSBuild.exe /p:DefineConstants=THING_TO_BE_DEFINED

我已经尝试了我能想到的所有变体:

MSBuild.exe "/p:DefineConstants=THING_TO_BE_DEFINED"
MSBuild.exe /p:DefineConstants="THING_TO_BE_DEFINED"
MSBuild.exe "/p:DefineConstants=THING_TO_BE_DEFINED=1"
MSBuild.exe /p:DefineConstants="THING_TO_BE_DEFINED=1"

...以及其他几十个。我还以类似的方式尝试过重写 PreprocessorDefinitions。它们都触发了下面的#error:

#include "stdafx.h"

#if !defined(THING_TO_BE_DEFINED)
#error "THING_TO_BE_DEFINED is not defined"
#endif

int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}

我一直在使用上面的简单命令行应用程序以及我这里的一个巨大的游戏项目进行尝试。我只能猜测 Visual Studio(我在 2005 年和 2008 年看到了这一点)在其内部深处设置了一些默认设置,阻止了我的命令行参数的应用,但我没有发现任何证据来支持这个假设。/p>

关于如何让它发挥作用有什么想法吗?为什么以 FSM 的名义,他们不坚持使用好的 ol'-D THING_TO_BE_DEFINED?

最佳答案

如果您在命令行上调用 MSBuild,则无法指定 DefineConstants 的值。但如果您正在构建 .csproj 或另一个 MSBuild 脚本,则可以指定它。如果您创建一个 msbuild 文件来“替换”您的解决方案文件,那么您可以在构建项目时使用该文件并为其指定值。例如:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Default value here -->
<DefineConstants Condition=" '$(DefineConstants)'==''" >DEBUG;TRACE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Projects Include="one.csproj" />
<Projects Include="two.csproj" />
</ItemGroup>

<Target Name="Build">
<MSBuild Projects="@(Projects)"
Properties="DefineConstants=$(DefineConstants)"/>
</Target>
</Project>

然后您可以使用msbuild.exe buid.proj/p:DefineConstants="YourValue;Debug;Trace"

注意命令行中引号的用法。

我不久前写了一篇关于与此相关的博客文章,网址为 http://sedodream.com/2008/05/07/MSBuildBuildingTheSameProjectMultipleTimes.aspx .

关于command-line - MSBuild.exe 不接受任一/p :DefineConstants nor/p:PreprocessorDefinitions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2016697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com