I have an ASP.NET application and I would like to set a variable during publishing the application depending on the environment (like production, quality, etc....) I have created a variable in the web.config file in appsettings section inside configration section like this:
<add key="RunningEnvironment" value="dev"/>
I have two profiles when deploying dev and prod
How can I set the RunningEnvironment variable in the web.cong depending on the profile I choose when deploying ?
Take a look at web.config transformations .
In your Web.Production.Config
for production environment set this:
<add xdt:Transform="Replace" xdt:Locator="Match(key)" key="RunningEnvironment" value="prod"/>
A handy tip you better know is Preview Transform dropdown menu option on Web.<ConfigurationName>.Config
file in Visual Studio. There you will see all the changes that are going to take effect.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.