1

MSBuildを使用してインストーラーのビルドを自動化しようとしています。私が直面した問題は、カスタムMSBuildスクリプトを呼び出しているC#プロジェクトのバージョン情報を取得することです。このスクリプトは、ビルドプロセス中にバージョン番号をWixに渡します。

私がしたいのは、バージョンを次のようないくつかのプロパティに設定することです。

<ProductVersion>$(MajorVersion).$(MinorVersion).$(PatchVersion).$(BuildVersion)</ProductVersion>
<InstallerName>"$(ProductName)-$(ProductVersion).msi"</InstallerName>

バージョンは継続的インテグレーションビルドの一部として更新され、継続的インテグレーションサーバー上に構築された各インストーラーにバージョン番号を組み込むことで、継続的インテグレーション可能なアプリケーションを作成できます。

どんな助けでも大歓迎です。

4

1 に答える 1

2

この問題を解決した方法は、コード リポジトリに「version.xml」ファイルを作成することです。このファイルには次のデータが含まれています

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5"
         DefaultTargets="Build"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <VersionMajor>0</VersionMajor>
        <VersionMinor>1</VersionMinor>
        <VersionBuild>1</VersionBuild>
        <VersionRevision>0</VersionRevision>
    </PropertyGroup>
</Project>

私の場合、このファイルはチェックインされていますが、ビルドサーバーからの情報や必要なものを使用してこのファイルを生成するのはそれほど難しくありません。

ビルド中、カスタム MBuild taks ( TemplateFile タスクと同様) は、それぞれのテンプレート ファイルからアセンブリ情報ファイルと Wix インクルード ファイルを作成します。「version.xml」ファイルは、MsBuild スクリプトに含めることでアクセスできます。たとえば、次のようにします。

<?xml version="1.0" encoding="utf-8"?>
<Project 
    ToolsVersion="4.0" 
    DefaultTargets="Build" 
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <!-- Include the version info file so that we can pull the version info from it -->
    <Import 
        Project="$(DirWorkspace)\version.xml" 
        Condition="Exists('$(DirWorkspace)\version.xml')" />

    <!-- Generate a file with the version information -->
    <Target Name="GenerateAssemblyInfoVersionNumber">
    <ItemGroup>
      <VersionTokens Include="Major">
        <ReplacementValue>$(VersionMajor)</ReplacementValue>
      </VersionTokens>
      <VersionTokens Include="Minor">
        <ReplacementValue>$(VersionMinor)</ReplacementValue>
      </VersionTokens>
      <VersionTokens Include="Build">
        <ReplacementValue>$(VersionBuild)</ReplacementValue>
      </VersionTokens>
      <VersionTokens Include="Revision">
        <ReplacementValue>$(VersionRevision)</ReplacementValue>
      </VersionTokens>
    </ItemGroup>
    <TemplateFile 
        Template="$(FileTemplateAssemblyVersion)"
        OutputFileName="$(FileGeneratedAssemblyVersion)" 
        Tokens="@(VersionTokens)" />
  </Target>
</Project>

C# プロジェクトに含まれる AssemblyInfo.VersionNumber.cs ファイルは、次のようなテンプレート ファイルから生成されます。

//-----------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost
//     if the code is regenerated.
// </auto-generated>
//-----------------------------------------------------------------------

using System.Reflection;

[assembly: AssemblyVersion("${Major}.${Minor}.${Build}.${Revision}")]
[assembly: AssemblyFileVersion("${Major}.${Minor}.${Build}.${Revision}")]

// The AssemblyInformationalVersion stores the version that will be displayed in
// Windows explorer.
[assembly: AssemblyInformationalVersion("${Major}.${Minor}.${Build}.${Revision}")]

置換プロセス中に、${TEXT_HERE}セクションはそれぞれの値に置き換えられます。

Wix インクルード テンプレート ファイルは次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <!--
      This is a generated file.
      Do NOT make changes to this file.
      They will be undone next time the file is generated.
    -->

    <!-- The current version -->
    <?define CurrentVersion = "${Major}.${Minor}.${Build}"?>

    <!-- The install version string -->
    <?define ProductVersionFolder = "${Major}.${Minor}"?>
</Include>

このファイルを含めた後、Wix インストーラーの必要な場所で変数を参照することができますCurrentVersionProductVersionFolder

この方法を使用すると、バージョン情報が 1 つの場所に保存され、ビルドのすべての部分からアクセスできます。

于 2013-02-18T23:51:31.253 に答える