MSBuild C ++ - 命令行 - 可以传递定义? [英] MSBuild C++ - command line - can pass defines?
问题描述
有一种方法可以转换这样的东西:
Is there a way to convert something like this:
#define ERROR_LOG_LEVEL 5
通过命令行将msbuild传递给它的项目?
Into something that msbuild via command line will pass to its projects?
msbuild.exe {???}ERROR_LOG_LEVEL=5 target
ve读取类似问题的答案,它看起来像是没有,只是想检查一下天才是否找到了解决方法。
I've read the responses to similar questions, and it looks like the answer is no, just want to double-check in case some genius has found a workaround.
推荐答案
宏可以通过传递 / D
选项给编译器。您可以使用 ClCompile $ c>的
AdditionalOptions
指定MSBuild中的 / D
$ c>:
Macros may be defined by passing the /D
option to the compiler. You can specify the /D
option from MSBuild using the AdditionalOptions
of ClCompile
:
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/DERROR_LOG_LEVEL=5 %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
如果要通过调用msbuild.exe传递宏的值,你也可以很容易地做到:
If you want to be able to pass the value for the macro via a call to msbuild.exe, you can easily do that too:
<ItemDefinitionGroup Condition="'$(ErrorLogLevel)' != ''">
<ClCompile>
<AdditionalOptions>/DERROR_LOG_LEVEL=$(ErrorLogLevel) %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
</ItemDefinitionGroup>
:
msbuild /p:ErrorLogLevel=5 MyProject.vcxproj
这篇关于MSBuild C ++ - 命令行 - 可以传递定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!