We need to define a conditional compilation symbol in a class library project. This should not be checked in the source control (it doesn't apply to all developers), so it should be defined in someplace other than the .csproj or the app.config file. How can this be achieved?
I would define your various build types in the configuration manager (menu Build → Configuration Manager) and set up each of the required constants on each of the build types.
You can then have each member of the team simply select the build type they want to do, and it will automatically use the appropriate constants. (I think that the most recently used build type is stored in the .suo file, which is "solution user options" and you wouldn't normally check in to your source control, so this would be maintained specifically for each user).
You can define pre-processor constants on the C# compiler command line using the /define switch, but you will have the problem of how to call this. Any changes you make to the project properties to use this will be saved in the .csproj file. You would have to do all of your building from the command line instead which I'm sure you won't want. You can also define them in MSBuild scripts, but you would have the same problem.
This works:
It turns out you can define conditional symbols in the csproj.user
file. I assume the same thing would work for other languages, but I haven't tried.
So just add something like the following to the csproj.user file.
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineConstants>MySpecialConstant, TestBlahBlah</DefineConstants>
</PropertyGroup>
I actually like @SimonPStevens solution better because it embraces TFS, instead of hiding. Sometimes, however, this is just easier...
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