How can I define conditional compilation symbols within solution?  
Author Message
WPF Fan





PostPosted: Visual C# IDE, How can I define conditional compilation symbols within solution? Top

Hi,

We have a solution with several c# projects within it.

How can I define solution wide conditional compilation symbols

I know how to define conditional compilation symbols at the project level,
but I don't want to define them in any single solution within the solution.

Thank you,

Alan

 



Visual C#7  
 
 
CRitchie





PostPosted: Visual C# IDE, How can I define conditional compilation symbols within solution? Top

Well the short answer is that you can't really.  But there are ways to handle what you are doing.  If I'm not mistaken when the compiler compiles a solution it uses the project file for conditional compilation symbols so the conditionals have to be defined at the project level.

Here is a way to do something like you are wanting.  The plan is to create a new build configuration.

1. Right click on your solution and select Configuration Manager...
2. In the Active Solution Configuration dropdown select <New>.
3. Enter the name of your new configuration in the form "configuration name""platform-name" (example DebugTest and ReleaseFinal).  Now there is a proper way to name your configuration due to the way the compiler looks for the configuration to build.  The first way is it looks for an exact name.  The second way is that it will look for a name that matches with the "configuration name" portion of the configuration name so that "DebugTest" also matches Debug if there is no DebugTest configuration in the project.  Then the last is to just use the very first configuration in the project's list of configurations.
4. Ensure "Also create new project configuration(s)" is checked.
5. Click OK.  Back in the Configuration Manager dialog ensure that all projects have the new configuration selected in the Configuration column.  This ensures that changes to each project configuration go to the correct build configuration.
6. Click OK.

Now go to each project's property page and define the appropriate conditional compilation symbols.  Yes I know you have to define them for each project but you'll only have to do it once.  Save the solution and all projects.

Now when you need to have that conditional compilation defined just select the newly defined configuration from the drop down in the IDE or in the configuration manager.

Is this something that would work for you

 
 
CRitchie





PostPosted: Visual C# IDE, How can I define conditional compilation symbols within solution? Top

One little edit:  the line "due to the way the compiler looks for the configuration to build" should read "due to the way the IDE assigns project configurations to be built".

The compiler does something completely different.  Look here:
http://msdn.microsoft.com/library/default.asp url=/library/en-us/vsintro7/html/vxconBuildConfigurations.asp



 
 
puy0





PostPosted: Visual C# IDE, How can I define conditional compilation symbols within solution? Top

Yes I know you have to define them for each project but you'll only have to do it once.


I know my comment coiuld look stupid, but anyway...
Never forget that projects .csproj files are "just" xml...