This is exactly what the web configuration transforms were created for. The link you provided in your post has a step-by-step guide for this, especially for connection strings.
To start with the transformations, right-click the web.config file in the project explorer and select Add Config Transforms. Assuming you have ConfigA and ConfigB in the configuration of your solution, two new files will be added: Web.ConfigA.config and Web.ConfigB.config.
If you open these new files, they will be pretty empty, except for a bunch of comments. They actually contain an example of a connection string in them that you can use - it looks like this:
<connectionStrings> <add name="MyDB" connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> </connectionStrings>
Uncomment this section and change the "name" property to the name of the connection string in the base web.config file. Set the connectionString property to the value you want to use for ConfigA. So, like this:
<connectionStrings> <add name="myConnectionString" connectionString="Data Source=ConfigASqlServer;Initial Catalog=ConfigADatabase;Integrated Security=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> </connectionStrings>
Repeat the process for the Web.ConfigB.config file with the desired connection string for ConfigB.
Now, when you use the Publish command in visual studio, it automatically converts the base web.config file and sets the connectionString attribute in whatever configuration you are in when you publish.
source share