Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
Markdown Monster - The Markdown Editor for Windows

No Compiler Directives in VS.NET 2005 Web Projects


:P
On this page:

Here’s another side effect of the project less ASP.NET projects in Visual Studio 2005: You loose the ability to use global compiler directives. I have a couple of projects that compile to different targets – one within a framework one just as a standalone and I’m using Compiler directives defined at the project level to cause a handful of changes in these ASP.NET projects.

 

This is a bummer… I haven’t been able to figure out a way to get around this short of hunting down these directives with Find All and then manually setting flags in these files.

 

This functionality might actually be there somewhere but I can't find it. I suspect not though because the Debug flag also isn't defined as it is in normal projects.

 

I haven’t looked at the new Web Project Add-in Microsoft put out a little while back – it probably supports this in 1.1 style project format.

 

On another note, I wish in general that there’d be a little better support for Includes of some sort. Yes, I’m very glad we don’t have C++ like Include file hell in .NET, which I presume is the reason for the lack of support for them. But it sure would be nice if you could define a project level #include file that contains all your defines and possibly has one global switch that you can control with an #IF statement. So instead setting several of these defines you can just create a couple of different build setups by changing things in one place.

 

Even better if there was a way to apply some of these on a solution wide level in VS.NET. With my current scenario even in the other ‘real’ projects (Controls, business objects, and general utility projects) each of those need to get those same flags set. So I have to add the defines at each project. I suppose I could create custom Configurations, but that’s a hassle and really seems overkill for something as simple as setting up some include flags.

 


The Voices of Reason


 

scottgu
December 26, 2005

# re: No Compiler Directives in VS.NET 2005 Web Projects

Hi Rick,

You can actually set compiler directives using your web.config file (including global #ifdefs). Scott Allen has a sample that shows how to-do this here: http://odetocode.com/Blogs/scott/archive/2005/12/01/2559.aspx

Note that values set this way will apply to the entire web project.

Hope this helps,

Scott

P.S. When you get a chance, I'd recommend checking out the new web project model option too. It does provide the same way to set this using the 1.1 project format.


Rick Strahl
December 26, 2005

# re: No Compiler Directives in VS.NET 2005 Web Projects

Thanks Scott,

I've downloaded and installed the new project model Add-in, but haven't time to check it out yet. I'll have some time this week - I'm in full on writing mode and the compilation stuff is one of the things I have to write up for an article, so I have to get to it...

Btw, for the rest of you if you haven't subscribed to Scott Allen's Blog (and Scott Gu's as well <g>) you should. Scott A. has been pumping out tons of very high quality and useful ASP.NET 2.0 content in the last few months...


West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2025