1

現在、WiX インストーラーの 1 つで、製品バージョン文字列を次のように明示的に定義しています。

<?define ProductVersion="1.2.3"?>

また、別のフォームのタイトルでも同じバージョン番号を使用しています。以下は、これがどのように適用されるかを示す非常に単純な例です。

public partial class frmMain : Form
{
    // assume the designer code is all properly generated

    private const string VERSION = "1.2.3";

    public frmMain()
    {
        InitializeComponent();
        this.Text += string.Format(" v{0}", VERSION);
    }
}

これは不格好に思えますが、製品バージョンを 2 か所で更新する必要はないと思います。バージョン文字列情報を保存するのに最適な場所はどこですか? 1 か所で更新するだけで済み、フォームとインストーラーの両方からこのデータを参照するだけで済みますか?

注意として、この場合、製品バージョンはアセンブリ バージョンと一致しません。

4

2 に答える 2

5

C# には、C/C++ や WiX ツールセットのようにプリプロセッサがないため、当然のことを実行してそのルート経由でバージョンを渡すことはできません。製品のバージョンがアセンブリファイルのバージョンと一致する場合は、次の操作を実行できます。

<Product Version='!(bind.fileVersion.FileIdOfAssembly)'>

ファイルのバージョンが一致していれば理想的です。そうでない場合、残っている唯一のオプションは、インストール時に何かを書き込み、実行時に読み取ることです。例えば:

<RegistryValue Root='HKLM'
               Path='SOFTWARE\!(bind.property.Manufacturer)\!(bind.property.ProductName)'
               Name='Version' Value='!(bind.property.ProductVersion)' Type='string' />

次に、そのレジストリ キーを frmMain() で読み取ります。現在、シンプルで堅牢なソリューションを使用しているため、アプリをさらに複雑にする価値があるかどうかはわかりません。

于 2013-04-13T05:32:43.537 に答える
1

I am not sure you would like to go through as much trouble as my solution will require, but here is it:

First, you should store assembly version in AssemblyInfo.cs file. This will allow sharing version (and other company - specific info) between projects just by referencing a common AssemblyInfo in all your projects. You can do it by adding existing file to a project as a link. For example, all our projects have two AssemblyInfo files: one local, project specific (GUID, etc...), and one common, with version info and company name.

[assembly: AssemblyFileVersion("1.3.100.25")]
[assembly: AssemblyVersion("1.1.0.0")]

Second, if you have not done this already, take the WIX version out of WXS file and put it into a separate WXI file. Again, this will allow separate editing of version (and other constants, if needed), and referencing it in several projects:

<?include ..\..\..\Common\WIX\Version.wxi ?>

Then, you will have to write a build task for MSBuild, and incorporate it as a pre-build dependency for all projects. In the build task, you can take version number from WXI file and put it into AssemblyInfo file, or vice versa. You can even store version data in a separate XML and inject it into both WXI and AssemblyInfo. Reading and writing WXI and AssemblyInfo is a simple string manipulation in C#, do not bother yourself with Reflection and stuff.

This third step is the only required one, and the most difficult. You should probably do all this if you have a lot of projects, or using automated builds.

于 2013-04-14T07:28:31.570 に答える