我有一个项目,其中为配置定义了预处理器常量
<DefineConstants>TRACE;DEBUG;VAR1</DefineConstants>
Run Code Online (Sandbox Code Playgroud)
我的代码可能是:
#if VAR1
Console.WriteLine("Var1");
#endif
#if VAR2
Console.WriteLine("Var2");
#endif
Run Code Online (Sandbox Code Playgroud)
我想执行 MSBuild 并定义常量 VAR2,而不覆盖配置中定义的常量
我尝试:
MSBuild MyProject.csproj /p:DefineConstants=VAR2
Run Code Online (Sandbox Code Playgroud)
但项目文件中定义的常量未设置:我的程序仅显示
变量2
我尝试过类似的事情但没有成功:
MSBuild MyProject.csproj /p:DefineConstants=$(DefineConstants);VAR2
Run Code Online (Sandbox Code Playgroud)
或者
<DefineConstants>$(DefineConstants);TRACE;DEBUG;VAR1</DefineConstants>
Run Code Online (Sandbox Code Playgroud)
这是一种合并项目中定义的常量和命令行上定义的常量的方法吗?
msbuild ×1