TFS 2012 and web.config transforms
Asked Answered
K

3

30

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?

Knighterrantry answered 1/5, 2013 at 2:37 Comment(0)
S
38

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/

Sennet answered 8/8, 2013 at 9:49 Comment(4)
Works for me! And kudos, your code sample here even fixes the typo from that blog post (that leaves a \ out in two places).Rincon
After I added those lines to csproj file during build I got an error: 'The "TransformXml" task was not found.' If somebody will have the same you can add this before this target <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets" Condition="!Exists('$(VSToolsPath)\Web\Microsoft.Web.Publishing.targets')" />Co
great, this worked for me (VS2015, TFS2015)! Many thanks! However, it is very strange that just specifying the build configuration is not enough.... MS sometimes make weird implementations...Aman
My VSTS build server is still ignoring the configuration and using the default debug web.config.Architrave
U
2

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)

Unopened answered 7/6, 2013 at 7:7 Comment(0)
K
1

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
Kew answered 8/8, 2013 at 15:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.