Conditional compilation symbols are those constants that you can define in order to include or exclude certain code in compilation of your solution. The most common constant is DEBUG. With DEBUG defined in your build configuration, you can define code that only gets compiled into the final binaries if compiled in the Debug build configuration. Below is an example of using the DEBUG constant to include code only when in Debug configuration.
#if DEBUG
Response.Write("The value of 'a' is " + a);
#endif
Since ASP.NET 2.0 projects do not have project files, there is no place in the Microsoft Visual Studio 2005 IDE to define the conditional compilation symbols like there is in DLL and Windows Executable projects.
It turns out that you can define these constants in your web.config. The downside to this is that they are not bound to a specific build configuration and so you will either have to manually add/edit these constants in your web.config or add something to your build process to handle these constants. Just add the xml below to your configuration of your web.config to define the DEBUG constant and a custom SANDBOX constant. (I like defining SANDBOX in order to hit against a developement/test database rather than the real/production database.)
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
compilerOptions="/d:DEBUG,SANDBOX"/>
</compilers>
</system.codedom>
Sunday, February 19, 2006
Conditional Compilation Symbols for ASP.NET 2.0 Projects
Labels:
Code
,
Technology
Subscribe to:
Post Comments (Atom)
1 comments:
Useful, just one typo:
compilerOptions="/d:DEBUG,SANDBOX" should contain ";" instead of "," (i.e. compilerOptions="/d:DEBUG;SANDBOX") when separating define symbols.
Post a Comment