TFS 2012 and web.config transforms

孤者浪人 提交于 2019-11-28 17:08:22

问题


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?


回答1:


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:


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)




回答3:


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


来源:https://stackoverflow.com/questions/16311981/tfs-2012-and-web-config-transforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!