I want to dynamically compile an ASP.NET website (project NOT) that has .csproj) depending on the configuration / characters I set. Therefore, in the configuration manager , I have the following:
DEVELOPMENT STAGING PRODUCTION
and Default.aspx.cs I have:
#if PRODUCTION lblMessage.Text = "PRODUCTION"; #elif STAGING lblMessage.Text = "STAGING"; #elif DEVELOPMENT lblMessage.Text = "DEVELOPMENT"; #endif
And in web.config I have:
<system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" compilerOptions="/d:DEVELOPMENT,STAGING,PRODUCTION" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </compilers> </system.codedom>
HOWEVER, no matter what configuration I choose (DEVELOPMENT, PROGRESS, PRODUCTION), I ALWAYS get a PRODUCT when I look at a web page (after rebuilding). Oddly enough, it always compiles everything I have in the "compilerOptions" attribute.
While I can find various questions with answers to this question, this does not work for me. I watched / tried this without success:
http://odetocode.com/blogs/scott/archive/2005/12/01/conditional-compilation-in-asp-net-2-0.aspx
Conditional compilation characters not defined
http://blog.aggregatedintelligence.com/2008/07/conditional-compilation-in-aspnet.html
Thanks!