C # Web Based Preprocessor Directives

I have a test and production web server. My project has a piece of code that I would like to place on a test server, but not on a production server.

#if (DEBUG) does not work because I prefer both to be published in RELEASE mode.

Is there a way to customize the preprocessor directive based on which web publishing profile is used?

+4
source share
1 answer

The easiest way to achieve this is to create separate build configurations for each environment in which you must publish. You can clone your new build configurations from Release. Then, in the project settings, enter the name of your assembly configuration in the conditional compilation symbol field.

So, for example, we have a Stage assembly configuration that is identical to Release, except that it defines the STAGE compiler constant. Then in the code you can use the #if (STAGE) checks.

+3
source

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


All Articles