如何合并命令行常量和配置常量 [英] How to merge constants of command line and constants of configuration

查看:48
本文介绍了如何合并命令行常量和配置常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个为配置定义了预处理器常量的项目

I have a project with a preprocessor constant defined for a configuration

<DefineConstants>TRACE;DEBUG;VAR1</DefineConstants>

我的代码可能是:

#if VAR1
        Console.WriteLine("Var1");
#endif
#if VAR2
        Console.WriteLine("Var2");
#endif

我想执行 MSBuild 并定义常量 VAR2 而不覆盖配置中定义的常量

I want execute MSBuild and define the constant VAR2 without override constants defined in the configuration

我试试:

MSBuild MyProject.csproj /p:DefineConstants=VAR2

但未设置项目文件中定义的常量:我的程序仅显示

But constants defined in the project file are not set : my program displays only

变量 2

我尝试过类似的事情没有成功:

I have tried things like without success :

MSBuild MyProject.csproj /p:DefineConstants=$(DefineConstants);VAR2

<DefineConstants>$(DefineConstants);TRACE;DEBUG;VAR1</DefineConstants>

有没有办法合并项目中定义的常量和命令行中定义的常量?

Is it a way to merge the constants defined in the project and constants defined on the command line?

推荐答案

AFAIK 通过命令行定义的属性将始终覆盖具有相同名称的静态定义的属性.作为一种解决方法,您可以将一个附加属性加入到 <DefineConstants/> 中,该属性未在您的项目文件中定义:

AFAIK a property defined via commandline will always override a statically defined property with the same name. As a workaround you can enqueue an additional property to <DefineConstants /> that is not defined in your project file:

<DefineConstants>TRACE;DEBUG;VAR1;$(MyCommandLineConstants)</DefineConstants>

并以这种方式调用 MSBuild:

and call MSBuild this way:

MSBuild MyProject.csproj /p:MyCommandLineConstants=VAR2;VAR3

这篇关于如何合并命令行常量和配置常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆