I have a project with a preprocessor constant defined for a configuration
<DefineConstants>TRACE;DEBUG;VAR1</DefineConstants>
My code could be :
#if VAR1
Console.WriteLine("Var1");
#endif
#if VAR2
Console.WriteLine("Var2");
#endif
I want execute MSBuild and define the constant VAR2 without override constants defined in the configuration
I try :
MSBuild MyProject.csproj /p:DefineConstants=VAR2
But constants defined in the project file are not set : my program displays only
Var2
I have tried things like without success :
MSBuild MyProject.csproj /p:DefineConstants=$(DefineConstants);VAR2
or
<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 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>
and call MSBuild this way:
MSBuild MyProject.csproj /p:MyCommandLineConstants=VAR2;VAR3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With