Site icon Tech Dreams

How To Define Conditional Compilation Symbols In MSBuild Automated C# Compilations [Programming]

In one of the mobile device application we are developing using .NET Compact Framework(C#) utilizes conditional compilation to include/exclude device specific source code. In Visual Studio, we can define the conditional compilation constants using “Conditional compilation symbols” input box in Build tab of Project Properties.

MSBuild and Conditional Parameters

Everything was working as expected until we checked in the source code and forced an automated build that makes use of MSBuild.exe to compile code. The problem is MSBuild not picking up the Conditional compilation symbols defined using Visual Studio properties page, so the code was not compiling as expected.

To resolve the issue we passed the required conditional compilation symbols to MSBuild command as extra parameters. Here is the extra parameters we specified to the command using /p":DefineConstants switch

 

              /p:DefineConstants="PocketPC,DEVICE"

 

Few points to note

Exit mobile version