MSBuild Script 和 VS2010 发布应用 Web.config 转换

MSBuild Script 和 VS2010 发布应用 Web.config 转换

问题描述:

所以,我已经安装了 VS 2010,并且正在修改我的 MSBuild 脚本以用于我们的 TeamCity 构建集成.一切正常,只有一个例外.

So, I have VS 2010 installed and am in the process of modifying my MSBuild script for our TeamCity build integration. Everything is working great with one exception.

如何告诉 MSBuild 我想要应用我在发布构建时创建的 Web.conifg 转换文件...

How can I tell MSBuild that I want to apply the Web.conifg transform files that I've created when I publish the build...

我有以下内容可以生成编译后的网站,但是,它将 Web.config、Web.Debug.config 和 Web.Release.config 文件(全部 3 个)输出到编译后的输出目录.在工作室中,当我执行发布到文件系统时,它会进行转换并只输出具有适当更改的 Web.config...

I have the following which produces the compiled web site but, it outputs a Web.config, Web.Debug.config and, Web.Release.config files (All 3) to the compiled output directory. In studio when I perform a publish to file system it will do the transform and only output the Web.config with the appropriate changes...

<Target Name="CompileWeb">
    <MSBuild Projects="myproj.csproj" Properties="Configuration=Release;" />
</Target>

<Target Name="PublishWeb" DependsOnTargets="CompileWeb">
    <MSBuild Projects="myproj.csproj"
    Targets="ResolveReferences;_CopyWebApplication"
    Properties="WebProjectOutputDir=$(OutputFolder)$(WebOutputFolder);
                OutDir=$(TempOutputFolder)$(WebOutputFolder);Configuration=Release;" />
</Target>

任何帮助都会很棒..!

Any help would be great..!

我知道这可以通过其他方式来完成,但如果可能的话,我想使用新的 VS 2010 方式来做到这一点

我一直在寻找类似的信息,但没有完全找到,所以我在 Visual Studio 2010 和 MSBuild 附带的 .targets 文件中进行了一些挖掘4.0.我认为这是寻找执行转换的 MSBuild 任务的最佳位置.

I was looking for similar information and didn't quite find it, so I did some digging around in the .targets files that come with Visual Studio 2010 and MSBuild 4.0. I figured that was the best place to look for the MSBuild task that would perform the transformation.

据我所知,使用了以下 MSBuild 任务:

As far as I have been able to tell, the following MSBuild task is used:

<Project ToolsVersion="4.0"
         DefaultTargets="Deploy"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <UsingTask TaskName="TransformXml"
               AssemblyFile="$(MSBuildExtensionsPath)MicrosoftVisualStudiov10.0WebMicrosoft.Web.Publishing.Tasks.dll"/>

    <PropertyGroup>
        <ProjectPath>C:Path to ProjectHere</ProjectPath>
        <DeployPath>C:Path to DeployThere</DeployPath>
        <TransformInputFile>$(ProjectPath)Web.config</TransformInputFile>
        <TransformFile>$(ProjectPath)Web.$(Configuration).config</TransformFile>
        <TransformOutputFile>$(DeployPath)Web.config</TransformOutputFile>
        <StackTraceEnabled>False</StackTraceEnabled>
    </PropertyGroup>


    <Target Name="Transform">
        <TransformXml Source="$(TransformInputFile)"
                      Transform="$(TransformFile)"
                      Destination="$(TransformOutputFile)"
                      Condition="some condition here"
                      StackTrace="$(StackTraceEnabled)" />
    </Target>
</Project>

我已经测试了以上内容并且可以确认它有效.您可能需要稍微调整结构以更好地适应您的构建脚本.

I have tested the above and can confirm that it works. You might need to tweak the structure a bit to fit with your build script better.