开发者

Automate VS 2010 "Publish" Config File Substitutions

I'm using the config file replacement feature of Visual Studio 2010's "Publish" functionality, as described in this article. I want to automate this using MSBuild/Hudson. Does anybody know how to do this?

I like how it works but if I cannot automate it开发者_如何学Go I'll have to switch to XmlMassUpdate or similar.


Explanation

To transform your config file you'll have to execute the TransformWebConfig target.

This target takes two files Web.config and Web.$(Configuration).config and generates a Web.config. The generated file is the transformed version of the original one for the current configuration.

This file is generated in folder : obj\$(Configuration)\TransformWebConfig

Usage

You don't really explain what you want to achieve, so here a basic usage, a job that generates a transformed config file in a given folder.

Add the following piece in the end of your project file *.csproj after the import of 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>

In Hudson you could add a Build step in your build, or create a dedicated job configured as follow:

  • MsBuild Build File : Your csproj file.
  • Command Line Arguments : /t:ConfigSubstitution /p:Platform=AnyCpu;Configuration=Test;TransformedWebConfigDestination=DestinationFolder


Edit your web project.csproj

under

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

Add -
<UseMsDeployExe>True</UseMsDeployExe>

Look at the Build output (make sure VS Tools - Options - Project & Solutions -Build & Run - MSBuild Output Verbosity - Detailed)

You should be able to see the msdeploy commands VS uses to produce the package. It's my understanding that VS actually uses Web Platform Pipeline API's and .target files to actually produce the deploy packages when building using MSBuild, and this command changes to use MsDeploy instead.

This stuff is so in need of documentation, its very frustrating.


I am using this in Hudson to target Release:

/Property:Configuration=Release

The exact settings are:

Build
MSBuild Version: msbuild-4 (configured to point to v4 msbuild)
MsBuild Build File: project_name.sln
Command Line Arguments: /Property:Configuration=Release

You can test this in your project directory by running something similar (as your .NET framework version may differ) to this:

%SYSTEMROOT%\Microsoft.NET\Framework\v4.0.30319\msbuild project.sln /Property:Configuration=Release

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜