views:

113

answers:

2

Dev Environment: XP SP3, VS2008, .NET 3.5, SQL Server 2005

I would like to know if there is a way to include different code to be compiled based on the solution configuration that is currently active. We typically have three configurations for our applications: Debug, Test, Production.

For example, I have an application that sends out an email. I would like to prepend the solution configuration name being used to the email subject if the configuration is not a production configuration.

+1  A: 

This depends on exactly what you want to do. An easy thing is that C# allows conditional compilation, and you can define the compilation symbols per-configuration:

#if DEBUG
// debug code
#else
// non-debug
#endif
John Saunders
John, thanks for the quick response. I saw this answer to a similar question but I wasn't sure it would apply here. I'll do a little research and give you a check if it works out.
JookyDFW
A: 

If you unload your project (in the right click menu) and add this just before the </Project> tag it will save out a file that has your configuration in it. You could then read that back in and use that to switch off of.

<Target Name="BeforeBuild">
    <WriteLinesToFile File="$(OutputPath)\env.config" 
                      Lines="$(Configuration)" Overwrite="true">
    </WriteLinesToFile>
</Target>
Vaccano