MSBuildでプロジェクト発行(昨日の続き)

subversionで更新→AssemblyInfoの更新→Configの更新→ビルド→発行をするMSBuildスクリプトができた。ちょっときたないスクリプトだけど、MSBuildが大体わかってきた。

設定ファイルの更新は、XmlUpdateを使いましたが、XmlMassUpdate*1も便利そうです。

<?xml version="1.0" encoding="utf-8"?>

<Project DefaultTargets="Run" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
  <!--<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets"/>-->
  <!--<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />-->

  <PropertyGroup>
    <SvnPath>E:/TracLight/subversion/bin</SvnPath>
    <Major>2</Major>
    <Minor>0</Minor>
    <Build>0</Build>
    <Revision>0</Revision>
    <OutputFolder>E:/temp/msbuildTest</OutputFolder>
  </PropertyGroup>

  <Target Name="Run">
    <CallTarget Targets="SvnUpdate"/>
    <CallTarget Targets="AssemblyInfo"/>
    <CallTarget Targets="Config"/>
    <CallTarget Targets="Build"/>
    <CallTarget Targets="Publish"/>
  </Target>

  <Target Name="SvnUpdate">
    <SvnUpdate LocalPath="$(MSBuildProjectDirectory)">
      <Output TaskParameter="Revision" PropertyName="Revision" />
    </SvnUpdate>
  </Target>

  <Target Name="AssemblyInfo">
    <Message Text="Version: $(Major).$(Minor).$(Build).$(Revision)"/>
    <AssemblyInfo CodeLanguage="CS"
      OutputFile="./MSBuildTest/Properties/AssemblyInfo.cs"
      AssemblyTitle="MSBuild Community Tasks"
      AssemblyDescription="Collection MSBuild Tasks"
      AssemblyCompany="http://example.org"
      AssemblyProduct="MSBuild.Community.Tasks"
      AssemblyCopyright="Copyright"
      ComVisible="false"
      CLSCompliant="true"
      Guid="Guid"
      AssemblyVersion="$(Major).$(Minor).$(Build).$(Revision)"
      AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)"
      Condition="$(Revision) != '0' "/>
  </Target>

  <Target Name="Config">
    <XmlUpdate
       XmlFileName="./MSBuildTest/ServiceReferences.ClientConfig"
       Xpath="//configuration/system.serviceModel/client/endpoint/@address"
       Value="localhost"/>
    <XmlUpdate
       XmlFileName="./MSBuildTest/ServiceReferences.ClientConfig"
       Xpath="//configuration/appSettings/add[@key='HogeHoge']/@value"
       Value="aaabbbccc"/>
  </Target>

  <Target Name="Build">
    <MSBuild Projects="./MSBuildTest.sln"
             Properties="Configuration=Release;"/>
  </Target>

  <Target Name="Publish">
    <RemoveDir Directories="$(OutputFolder)"
               ContinueOnError="true" />
    <MSBuild Projects="./MSBuildTest.Web/MSBuildTest.Web.csproj"
             Targets="ResolveReferences;_CopyWebApplication"
             Properties="Configuration=Release;
                         WebProjectOutputDir=$(OutputFolder);
                         OutDir=$(OutputFolder)/"/>
  </Target>
</Project>