views:

483

answers:

2

I am attempting to make it so that we can have our application to behave differently based on the presence of a preprocessor directive. I've read that you can create build configurations to define different preprocessor directives based on which build you do. Well, I am not seeing anything in Visual Studio to do this.. I know how to do it from the command line, but not how to do it within the automated environment of VS 2008.

Can someone tell me how to create a new build configuration which has preprocessor directives set in it?

Also, not sure if it has anything to do with it, but our project is an ASP.Net website

+2  A: 

If you right-click the project and select "Properties", then select the Build tab, you can enter custom compilation symbols in "Conditional compilation symbols".

For example, if your code looks like this:

#if DEBUG
// do something
#else
// do something else
#end

You can set "DEBUG" as a Conditional compilation symbol.

You can set different values for different build configurations, by changing the "Configuration" drop-down.

Andy White
this is what I read everywhere and the only thing I see is "start action" "target framework" "build solution action" "accessibility validation".. nothing about the preprocessor is listed anywhere that I can find. @your edit: there does not exist a tab or anything for entering "conditional compilation symbols"
Earlz
Interesting, what type of project is it? On my build tab, it shows sections like "General", "Errors and Warnings", "Treat warnings as errors" and "Output". The "Conditional compilation symbols" section is under General.
Andy White
I do not even see a way to control the DEBUG symbol. and it is an ASP.Net website. I'll post a screen shot.
Earlz
+2  A: 

I do not even see a way to control the DEBUG symbol, and it is an ASP.Net website

Ok, there's the problem. The ASP.net web site option gives you a lot less control over builds, etc as it doesn't even use a project file.

If it is at all feasible for you to switch, switch over to an ASP.net web application. A web app will behave much more like a typical C# project (you have a project file, and the contents of the csproj file control what is in the app instead of just the directory structure, etc.

After you have converted, you should see the options that you are expecting.

Here's a link with directions for converting: http://stackoverflow.com/questions/735054/how-to-convert-asp-net-website-to-asp-net-web-application

JMarsch