Search code examples
c#visual-studio-2008conditional-compilation

Trying to simplify the steps for Conditional Compilation in C#


Background:

What i'm trying to do is to customize the build procedure for my project in the VS2008 IDE based on the set of configuration i need at a given point of time.

My project has some conditional methods e.g.[Conditional("FULLFEATURE")] or [Conditional("LESSFEATURE")] which execute only when i mention the FULLFEATURE or LESSFEATURE conditional compilation symbol in the Build project properties.

This approach is laborious as each time when i have to compile through the (VSNET IDE) i have to manually add a compilation symbol depending on my requirement.

Question

Is there a way where in i can avoid this ( maintain two different copies of project for each feature, No i don't want this approach) ?

Is there a way through the configuration manager wherein i can just select one amongst

FULLFEATURE --> Debug ---> x86
FULLFEATURE --> Debug ---> AnyCPU
FULLFEATURE --> Release ---> x86
FULLFEATURE --> Release ---> AnyCPU


LESSFEATURE --> Debug ---> x86
LESSFEATURE--> Debug ---> AnyCPU
LESSFEATURE--> Release ---> x86
LESSFEATURE--> Release ---> AnyCPU  

to build in whatever configuration i need. I know this approach is going to get nasty if i have more number of conditional compilation symbols. But here i am ..

Any suggestions most welcome

Cheers


Solution

  • Build + Configuration Manager. Use the upper left combobox labelled "Active solution configuration" and select New.... Type a new name. Project + Properties, Build tab and set your conditional. Each configuration will now have its own conditionals.

    You now simply switch between configurations with the configuration selector on the toolbar and build/debug as needed.