views:

856

answers:

3

I'm attempting to make use of configuration transformations in a continuous integration environment.

I need a way to tell the TFS build agent to perform the transformations. I was kind of hoping it would just work after discovering the config transform files (web.qa-release.config, web.production-release.config, etc...). But it doesn't.

I have a TFS build definition that builds the right configurations (qa-release, production-release, etc...) and I have some specific .proj files that get built within these definitions and those contain some environment specific parameters eg:

<PropertyGroup Condition=" '$(Configuration)'=='production-release' ">
    <TargetHost Condition=" '$(TargetHost)'=='' ">qa.web</TargetHost>
    ...
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)'=='qa-release' ">
    <TargetHost Condition=" '$(TargetHost)'=='' ">production.web</TargetHost>
    ...
</PropertyGroup>

I know from the output that the correct configurations are being built. Now I just need to learn how to trigger the config transformations. Is there some hocus pocus that I can add to the final .proj in the build to kick off the transform and blow away the individual transform files?

A: 

Any lucky with it?

I'm having a nightmare to automate deployments and your problem comes along with it...

hudsonmendes
+1  A: 

All you should need to do is setup which configuration should be used within the TFS build definition.

  1. Goto Team Explorer > Builds
  2. Edit your build definition (or create new)
  3. Under the "Process" step there is a settings for "Configurations to Build".

In my case I have setup a configuration specifically for CI that then performs the correct web.config transformations. Ensure that you have added the "CI" transform file and you should be good to go.

Wallace Breza
Also note that the web.config transforms are only called during deployment and not during standard builds.
Wallace Breza
+3  A: 

I finally managed to get this working. I'm using TFS 2008, but also using MSBuild 4.0 so it should work for you.

First, add this import to TFSBuild.proj:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

Next, add a BeforeDropBuild target:

<Target Name="BeforeDropBuild">
  <TransformXml Source="$(SolutionRoot)\MySite\Web.config"
    Transform="$(SolutionRoot)\MySite\Web.QA.config"
    Destination="$(OutDir)\_PublishedWebsites\MySite\Web.QA.config.transformed" />
</Target>

You can then copy the Web.QA.config.transformed to wherever you need it to go.

Rohan Singh
TFSBuild.proj no loner exists in TFS 2010 which this question relates too. They use a new workflow based build system. I havent figured out how to transofrm the web.config yet as I need to do this aswell ...
Steve Ward
We just upgraded to TFS 2010. The consultant who did the upgrade setup some sort of backward-compatibility workflow that uses our existing TFSBuild.proj files for now. Sure we're going to regret it later, but this is still working with Team Build 2010 for us for now...
Rohan Singh