Blog Archives
Integrating Web Config Transformations with TFS Build
Web Config Transformations a new feature available with .NET Framework 4.0 allows us to alter the configuration settings depending on the application target environment. Transformations are specified using Locator and Transform attributes within your configuration elements. You need to qualify these transformations with corresponding XML namespace as shown below (extract of sample web.staging.config):
<configuration xmlns:xdt=”http://schemas.microsoft.com/XML-Document-Transform”>
<connectionStrings>
<add name=”DBConnString” … xdt:Transform=”Replace” xdt:Locator=”Match(name)”
/>
</connectionStrings>
…
It’s important to note the outer elements (configuration/connectionStrings) which form the effective path of the XPath Expression. If Locator is missing implicit path is considered of the current element is considered which needs to be transformed. Locator attribute provides operations like Condition, Match and XPath to locate elements. Transform attribute provides operations like Replace, Insert, InsertBefore, InsertAfter, Remove, RemoveAll, RemoveAttributes, and SetAttributes among others.
Ideal productivity booster would be to integrate these transforms into our TFS Builds. So we select a build configuration and trigger a build and build picks up the corresponding transforms to be applied. Let’s see how we can do that.
To start with you need to add a new Solution Configuration using Configuration Manager.
Right click the web.config and select ‘Add Config Transforms’
You can use the newly created file – ‘Web.Staging.Config’ to add all the transformations. Next step is to create a new TFS Build definition. While creating a new definition you need to specify ‘Staging’ for configuration build (this has to be a manual entry as the drop down would only support Debug / Release). We also pass an argument to via build definition (IsTFSBuild) in this case. Provide all the entries as appropriate inside the build definition.
Final step is to modify your CSPROJ file (you could have modify the BuildTemplate workflow but that’s not for faint hearted like me). Add the MSBuild target element as below which checks the ‘IsTFSBuild’ flag and applies the necessary transformations
<Target Name=”AfterBuild” Condition=”$(IsTFSBuild)==’True’”>
<ItemGroup>
<DeleteAfterBuild Include=”$(WebProjectOutputDir)\Web.*.config” />
</ItemGroup>
<TransformXml Source=”Web.config” Transform=”$(ProjectConfigTransformFileName)” Destination=”$(WebProjectOutputDir)\Web.config” />
<Delete Files=”@(DeleteAfterBuild)” />
</Target>
You may not find necessary MSBuild tasks like ‘TransformXml’ on your build machine. You would have to copy the below shown files to the MSBuild directory
Hope this sets you up for higher levels of productivity
.
Connecting to TFS 2010 using Team Explorer 2008 / Visual Studio 2008
This has been quite a common scenario especially around Business Intelligence projects which are still only supported out of Visual Studio 2008. So you often want these BI projects to connect to TFS 2010, which could be your centralized version control among others. Below are the steps for the same, assuming you have already installed Visual Studio 2008:
a) Install Team Explorer 2008
b) Install VS.NET 2008 SP1
c) Install forward compatible Update for Team Explorer 2008 to make it work with TFS 2010
d) Go to your VS.NET 2008 Team Explorer and adding a server by specifying full URL as shown below
Hope that helps!!!





