Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MsBuild with solution files with DefineConstants

Currently, in my automated build, I use the devenv.exe to build my solution files:

devenv /build myproject1.sln

Now, I want to create two versions of my application, the normal version, and the light version. The source code for these two versions are the same, it's just that in light version some of the features are disabled, and for this I use #define lite preprocessor directives ( In csproject file, these constants are defined under DefineConstants Property Group).

In MsBuild--or just normal devenv build--is it possible to specify whether the symbol I want should be present in the build? The reason I ask this is because I want to build my sln file first time with the lite preprocessor directives ( for lite version), and the second time, without the lite preprocessor directives ( for full version).

like image 642
Graviton Avatar asked Feb 19 '11 06:02

Graviton


2 Answers

In your project file add new PropertyGroup section for lite version

<PropertyGroup Condition="'$(LiteVersion)'=='true'">
   <DefineConstants>$(DefineConstants);lite</DefineConstants>
</PropertyGroup>

Remove lite from all definitions of DefineConstants.

MSBuild.exe  myprojeect1.sln
MSBuild.exe  myprojeect1.sln /p:LiteVersion=true

You can create additional configuration in VS to switch between versions. But it can lead to configuration mismatches when you forgot to add a flag to lite config. I can suggest more elegant solution. Create .bat file or change the link to run myproject1.sln:

set LiteVersion=true
devenv.exe myproject1.sln
like image 194
Sergio Rykov Avatar answered Sep 26 '22 23:09

Sergio Rykov


Create two configurations in your sln file - one for the Lite and one for the Normal. In the Lite config, define the preprocessor directive via the Project Properties dialog.

Then, when doing the build using devenv.com, specify the correct configuration in which to build.

like image 31
logicnp Avatar answered Sep 23 '22 23:09

logicnp