30
votes

I am trying to have my TFS Build create the web.config transform associated with the configuration I selected for my build. When I run the build I check the web.config file no transforms have been applied. When I a publish from VS2012 the transform works correctly.

I have set up TFS 2012 (Update 2), and have a separate server for builds. I don't have VS2012 installed on the build server, but I copied the C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\ Web and WebApplications folders and files from my dev machine to the build server.

I have created some configurations in my project, and have added some tranforms to the associated web.{configname}.config.

I have created a build and set the Items to Build - Configurations to Build to one of the configurations in my project. I noticed that it only has Debug and Release, it didn't have any of the configurations I created. (Side question: Is that correct, or should it show all the configurations I created?)

So I run a build and check the output folder and the web.config has not applied the transforms. Is there anything else I need to do?

3

3 Answers

38
votes

Just throwing /p:TransformConfigFiles=true on there won't actually do anything.

You also need to add this target to the project file:

<Target Name="TransformConfigFiles" AfterTargets="AfterBuild" Condition="'$(TransformConfigFiles)'=='true'">
    <ItemGroup>
        <DeleteAfterBuild Include="$(WebProjectOutputDir)\Web.*.config" />
    </ItemGroup>
    <TransformXml Source="Web.config" Transform="$(ProjectConfigTransformFileName)" Destination="$(WebProjectOutputDir)\Web.config" />
    <Delete Files="@(DeleteAfterBuild)" />
</Target>

This is my source: http://blog.degree.no/2012/03/automatic-config-transformations/

2
votes

You can type-in the name of Configuration in "Items to Build->Configurations to build" list.

If that doesn't help, try to add following MSBuild argument: /p:TransformConfigFiles=true (3. Advanced -> MSBuild Arguments)

1
votes

Right click your solution file, go to properties, click configuration properties, and click configuration Manager on the top. Make sure your configuration for different environment set properly. if it is not set properly, set it properly and check in the code. Now go to your build template and check the configuration to build property in the process tab, you must be able to see your different configurations. if the configuration is already set it properly, you can also add the new configuration name by typing it in the build property.

Note: you can also right click your web.config transform file and choose preview transform and make sure the transform config is working fine.

you can also give the publish profile name, if it is working properly int he msbuild arguments section

/p:DebugSymbols=false;DebugType=None;DeployOnBuild=true;PublishProfile=Stage