MSBuild项目部署到配置转换的本地文件夹 [英] MSBuild project deploy to local folder with config transformed

查看:169
本文介绍了MSBuild项目部署到配置转换的本地文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到正确的方法来使用MSBuild来构建一个Web项目,并且仅使用可部署的文件(即没有.cs,.csproj,.Debug.config等)输出项目,而是发布到一个本地文件夹,然后我可以FTP,RoboCopy,(或任何)到次要位置。

I'm having trouble trying to find the right way to use MSBuild to build a web project and output the project with only deployable files (i.e. no .cs, .csproj, .Debug.config etc.), but published to a local folder that I can then FTP, RoboCopy, (or whatever) to a secondary location.

发布的输出必须具有根据原始转换的Web.config文件输出中包含指定的配置和转换配置文件(例如Web.Debug.config)。我不需要任何花哨的发布到IIS,数据库部署或任何类似的东西,我只想要干净的文件系统输出,我可以然后测试。请注意,这不能使用可视化工具,因为我想将其作为自动构建过程的一部分运行。

The published output must have the Web.config file pre-transformed as per the specified configuration and the transformation config files (e.g. Web.Debug.config) not included in the output. I don't need any fancy publishing to IIS, database deployment or anything like that, I just want clean file system output that I can then test. Note that this cannot be done using visual tools as I want to run it as part of an automated build process.

我可以生成一个Web部署包,但是我可以'让WebDeploy工作,因为它似乎没有处理引用的命令行选项(似乎是某种错误),目录结构有空格,所以我希望使用MSBuild完成整个任务,看起来像MSBuild似乎具有转换配置文件( TransformXml )的本地容量,这是我将要使用的正确部署功能的唯一真正的一部分。

I can generate a web deployment package, but I can't get WebDeploy to work because it doesn't seem to handle quoted command line options anymore (seems to be some kind of bug) and the directory structure has spaces, so I was hoping to accomplish the whole task using MSBuild, seeing as MSBuild seems to have native capacity to transform the config file (TransformXml), which is the only real bit of proper deployment functionality I'd be using.

推荐答案

最终得出结论。以下构建脚本的作法是:

Got it figured out eventually. The following build script does the trick:

<?xml version="1.0"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>
    <PropertyGroup>
        <OutputDir>obj\website-output</OutputDir>
    </PropertyGroup>
    <Target Name="PrepareDeploy">
        <ItemGroup>
            <DeployableFiles Include="App_Code/**/*.*;App_Data/**/*.*;Areas/**/Views/**/*.*;bin/**/*.*;Views/**/*.*;*.aspx;*.asax;*.html;*.htm;sitemap.xml;*.ico;*.png" Exclude="App_Data/**/*.log" />
        </ItemGroup>
        <RemoveDir ContinueOnError="true" Directories="$(OutputDir)" />
        <MSBuild Projects="Website.csproj" />
        <MakeDir ContinueOnError="true" Directories="$(OutputDir)" />
        <Copy SourceFiles="@(DeployableFiles)" DestinationFiles="@(DeployableFiles->'$(OutputDir)\%(RelativeDir)%(Filename)%(Extension)')" />
        <TransformXml Source="Web.config" Transform="Web.$(Configuration).config" Destination="$(OutputDir)\web.config" />
    </Target>
</Project>

这篇关于MSBuild项目部署到配置转换的本地文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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