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?

4

3 回答 3

38

只是在那里扔 /p:TransformConfigFiles=true 实际上不会做任何事情。

您还需要将此目标添加到项目文件中:

<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>

这是我的来源:http ://blog.degree.no/2012/03/automatic-config-transformations/

于 2013-08-08T09:49:13.887 回答
2

您可以在“要构建的项目->要构建的配置”列表中输入配置的名称。

如果这没有帮助,请尝试添加以下 MSBuild 参数:/p:TransformConfigFiles=true (3. Advanced -> MSBuild Arguments)

于 2013-06-07T07:07:11.390 回答
1

右键单击您的解决方案文件,转到属性,单击配置属性,然后单击顶部的配置管理器。确保正确设置不同环境的配置。如果设置不正确,请正确设置并检查代码。现在转到您的构建模板并检查配置以在进程选项卡中构建属性,您必须能够看到您的不同配置。如果配置已经正确设置,您还可以通过在构建属性中键入新的配置名称来添加它。

注意:您也可以右键单击您的 web.config 转换文件并选择预览转换并确保转换配置工作正常。

如果它在 msbuild 参数部分中正常工作,您还可以提供发布配置文件名称

/p:DebugSymbols=false;DebugType=None;DeployOnBuild=true;PublishProfile=Stage
于 2013-08-08T15:30:39.393 回答