Dynamically compiled ASP.NET website

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!

+4
source share
1 answer

This would be better handled by using build configurations in the project. Probably the correct characters are not currently defined. By default, there is a debug and release configuration. You need to create / edit your assembly configurations according to your characters. This method allows you to simply select the assembly configuration that you would like to use from the pop-up assembly and assembly configuration dialog box.

In addition, there were many projects that I drew myself in the corner with all sorts of #if DEBUG frenzy. If you can deduct these conventions in your configuration files and implement configuration conversions , then you will make your life (or your successor) easier in the future,

0
source

Source: https://habr.com/ru/post/1498999/


All Articles