Web Config Transformations

Web config transformations allow for developers to cut down on duplicated XML in configuration files by providing a way to change only the non-static values for the appropriate environment. A value that would be expected to change between environments is something like a connection string, whereas library versions would remain the same for any deployment of an application.

Transformations can be tricky: often times developers do not have the required access to view the transformed version of the file on a production environment. The best way to configure your transformations is to use a site like the one below which uses the same transformation functions as the build and shows you the output.

https://webconfigtransformationtester.apphb.com/

https://msdn.microsoft.com/en-us/library/dd465326(v=vs.110).aspx

The second link above is to Microsoft's documentation of the possible transforms. The key takeaway from this reference is the purpose of Transform and Locator. Transform is used to decide what to change in the config. If you include a snippet of XML that contains a new connection string, for example, and do NOT include a keyword like xdt:Transform="", then no transformation will be made BUT the web config will compile! This is the most common way to cause undetected transform issues. Breaking errors will be caused by invalid use of transformation keywords like using "insert" when the specified module is already there.

The Locator attribute is how you apply conditions to the transformation. A common instance is to check if the value you are trying to replace is equal to the old value, and only replace if that is the case. If you don't specify a Locator attribute, the default behavior is to match the module that has the Transform attribute.

Thanks for reading!

Comments

Popular posts from this blog

ASP.NET Identity Remember Me

IIS Express Client Certificates

ASP.NET MVC - How to enable/disable CaC/Client Certificate authentication per area or route.