Reputation: 1668
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.
Upvotes: 1
Views: 820
Reputation: 82351
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>
Upvotes: 1
Reputation: 161773
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
Upvotes: 2