How to define conditional compilation symbols in separate file (not .csproj or app.config)
Asked Answered
P

2

6

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?

Palestine answered 3/8, 2009 at 9:10 Comment(0)
B
10

I would define your various build types in the configuration manager (menu BuildConfiguration 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.

Boondocks answered 3/8, 2009 at 9:36 Comment(0)
D
9

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...

Dung answered 3/10, 2013 at 16:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.