Convert Web.config Variables

Can variables be included in the web.config conversion file? For each environment, I have basically the same transformation, only with different values. For example, for a development environment, I would have ...

<?xml version="1.0"?> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <appSettings> <add key="serverName" value="server1" xdt:Transform="Replace" xdt:Locator="Match(key)" /> <add key="serverPath" value="\\server1" xdt:Transform="Replace" xdt:Locator="Match(key)" /> </appSettings> </configuration> 

And for a QA environment, I would have ...

 <?xml version="1.0"?> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <appSettings> <add key="serverName" value="server2" xdt:Transform="Replace" xdt:Locator="Match(key)" /> <add key="serverPath" value="\\server2" xdt:Transform="Replace" xdt:Locator="Match(key)" /> </appSettings> </configuration> 

The only difference is the value for server1 vs server2. This is a simple example, and in fact I use the server value several times in the conversion. Is there a way to declare a variable in a transform file that will be used multiple times? Something like...

 <?xml version="1.0"?> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <property name="server" value="server2" /> <appSettings> <add key="serverName" value="${server}" xdt:Transform="Replace" xdt:Locator="Match(key)" /> <add key="serverPath" value="\\${server}" xdt:Transform="Replace" xdt:Locator="Match(key)" /> </appSettings> </configuration> 
+7
source share
2 answers
+1
source

it is not supported by web.config conversions. You can take a look at creating the T4 Template , which you can use to create web.config transformations. So the idea is that you put the variables in the T4 template and it spits out the web.debug.config / web.release.config / etc file. Then, when you package / publish, it just picks up the conversion file that was created as T4 output.

I would not mind helping you in such a situation if you can give some specific examples of how this is useful.

+4
source

All Articles