开发者

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 version开发者_StackOverflow中文版s 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).


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜