web.config transformation/Tokenization


Web.config Transformation:
We normally have the different connectionStrings and appSettings in web.config for Development and Prod. Visual studio has the auto transformation feature that transforms the web.release.config to web.config file. so, we can place the dev env  config settings in web.config and prod env config settings in web.release.config. while visual studio publish, it transforms env config settings into the web.config.
To transform/create web.release.config right click on the web.config and select Transform web.config in the context menu

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
      <add name="giriWebDev" connectionString="####" xdt:Locator="Match(name)" xdt:Transform="SetAttributes"/>
     <add key="Env" value="Prod" xdt:Locator="Match(key)" xdt:Transform="SetAttributes"/>
    <compilation xdt:Transform="RemoveAttributes(debug)" />

As you see, the xdt:Locator & xdt:Transform attirbutes do the transformation of config setting values in web.config during the publish process in visual studio. You can see the transform info in vs output window.

The xdt:locator attribute identifies/searches the config setting in *.config file by its key/name. When it found, the xdt:transform copys the attribute value from web.release.config to web.config.

we can replace the whole connectionStrings setting by xdt:Transform="Replace"

<connectionStrings xdt:Transform="Replace">
      <add name="giriWebDev" connectionString="####"/>


Average Rating: 0.00 by 0 users

Download PDF