自动化VS 2010"发布"配置文件替换

rou*_*tic 7 msbuild hudson visual-studio-2010

我正在使用Visual Studio 2010的"发布"功能的配置文件替换功能,如本文所述.我想使用MSBuild/Hudson自动执行此操作.有人知道怎么做这个吗?

我喜欢它是如何工作的,但如果我不能自动化它,我将不得不切换到XmlMassUpdate或类似的.

Jul*_*rau 5

说明

要转换配置文件,您必须执行TransformWebConfig目标.

这个目标有两个文件Web.config,并Web.$(Configuration).config和生成Web.config.生成的文件是当前配置的原始文件的转换版本.

此文件在文件夹中生成: obj\$(Configuration)\TransformWebConfig

用法

你没有真正解释你想要实现的目标,所以这里有一个基本用法,一个在给定文件夹中生成转换配置文件的作业.

*.csproj导入后,在项目文件末尾添加以下部分Microsoft.WebApplication.targets

<PropertyGroup>
  <!-- Directory where your web.config will be copied -->
  <TransformedWebConfigDestination>$(MSBuildProjectDirectory)</TransformedWebConfigDestination>
</PropertyGroup>

<!--
  This target transforms the web.config based on current configuration and
  put the transformed files in $(TransformedWebConfigDestination) folder
-->
<Target Name="ConfigSubstitution">
  <CallTarget Targets="TransformWebConfig"/>

  <ItemGroup>
    <TransformedWebConfig Include="obj\$(Configuration)\TransformWebConfig\Web.config"/>
  </ItemGroup>

  <!-- Copy the transformed web.config to the configured destination -->
  <Copy SourceFiles="@(TransformedWebConfig)"
        DestinationFolder="$(TransformedWebConfigDestination)"/>
</Target>
Run Code Online (Sandbox Code Playgroud)

Hudson中,您可以在构建中添加Build步骤,或者创建一个配置如下的专用作业:

  • MsBuild构建文件: Your csproj file.
  • 命令行参数: /t:ConfigSubstitution /p:Platform=AnyCpu;Configuration=Test;TransformedWebConfigDestination=DestinationFolder

  • 对于未来的搜索者来说,看起来您只需要.NET 4.0 Framework +几个额外的vs2010文件来进行4.0构建.http://www.scmgalaxy.com/release-updates/161-running-msbuild-40-and-msbuild-35-on-continuous-integration.html (2认同)