MSBuild的脚本和VS2010发布应用的Web.config变换 [英] MSBuild Script and VS2010 publish apply Web.config Transform

查看:242
本文介绍了MSBuild的脚本和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)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>

    <PropertyGroup>
        <ProjectPath>C:\Path to Project\Here</ProjectPath>
        <DeployPath>C:\Path to Deploy\There</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.

这篇关于MSBuild的脚本和VS2010发布应用的Web.config变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆