One of the features I really like is the web.config transformations; this is exactly what I’ve been looking for in Sitecore installs. When you’re deploying Sitecore to a production server there is always a raft of settings that need changing, you can manually keep track of them or use features like configSource attributes but there always seems to be problems. In VS2010 however you can keep a set of transformation web.configs for your various deployments:
Part of the MSBuild deployment process is that it creates a new web.config with the changes you’ve specified in the transformation files. The files themselves contain the settings that need changing and details on how to match them within the original web.config:
<?xml version="1.0"?> <!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <connectionStrings configSource="App_Config\ConnectionStrings.Debug.config" xdt:Transform="Replace" /> <sitecore database="SqlServer"> <sc.variable name="dataFolder" value="E:\WebApplications\vs2010test\data" xdt:Transform="Replace" xdt:Locator="Match(name)" /> <sites> <site name="vs2010test_english" xdt:Transform="Replace" xdt:Locator="Match(name)" language="en" hostName="english.vs2010test.local" ... <site name="vs2010test_japanese" xdt:Transform="Replace" xdt:Locator="Match(name)" language="ja-JP" hostName="japanese.vs2010test.local" ... <site name="vs2010test_german" xdt:Transform="Replace" xdt:Locator="Match(name)" language="de-DE" hostName="german.vs2010test.local" ... </sites> <settings> <setting name="IndexFolder" xdt:Transform="Replace" xdt:Locator="Match(name)" value="E:\WebApplications\vs2010test\data\indexes" /> </settings> </sitecore > <system.web> <customErrors mode="RemoteOnly" xdt:Transform="Replace"/> </system.web> </configuration>
The important attribute is xdt:Transform=”Replace” which replaces the setting in the original web.config with the new one. This works fine when there is just a single node of that type such as <connectionStrings/>.
For nodes with multiple instances such as <site/> you can distinguish them using xdt:Locator=”Match(name)” which tells the transformer to match the element to the original using the name attribute.
Once all the changes are made you should end up with a new web.config that is configured for your deployment target machine. There is the added bonus that all of these transform files are stored in source control alongside the original web.config.
I’ve also been looking at the Team Development for Sitecore product from Hedgehog software (deserves own blog post), combined with this and I think my deployment issues will be solved. Hopefully