ASP.NET how to set a variable in web.config during publising an app

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 ?

Answers


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.


Need Your Help

How to insert string containing single or double quotes

c# sql sql-server-2008

If I want to insert a statement which contains quotation mark, how is it possible ?

ADAL iOS Redirect URI must be http(s)?

ios adal

I'm working to get ADAL auth working in my iOS app (Xcode 8, running on iOS 10) using the latest version of the ADALiOS library (2.2.5) and have configured the authContext according to the document...