C# 如何将 WiX 安装程序版本设置为当前构建版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/626033/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 10:48:16  来源:igfitidea点击:

How can I set the WiX installer version to the current build version?

c#svnwix

提问by Draco

I wrote an application and its WiX installer and put it under version control using subversion. When the WiX installer builds I want its version number to be the current build version of the application. How do I accomplish this? I used c# to code the application.

我编写了一个应用程序及其 WiX 安装程序,并使用 subversion 将其置于版本控制之下。当 WiX 安装程序构建时,我希望它的版本号是应用程序的当前构建版本。我该如何实现?我使用 c# 来编写应用程序。

N.B. I am using ccnet to build this project

注意我正在使用 ccnet 来构建这个项目

采纳答案by Rob Mensching

You could use Product/@Version="!(bind.FileVersion.FileId)"(replace FileIdwith the Idof the file from which you'd like to get the version number) and light.exe will populate the value with the version of the file referenced by the FileId.

你可以使用Product/@Version="!(bind.FileVersion.FileId)"(替换FileIdId从您想要得到的版本号文件)和light.exe将被引用的文件的版本填充值FileId

回答by JohnW

This looks reasonably close to what you are trying to accomplish. See what the equivalent is in cruise control.

这看起来与您要实现的目标相当接近。看看巡航控制中的等价物是什么。

http://www.ageektrapped.com/blog/setting-properties-for-wix-in-msbuild/

http://www.ageektrapped.com/blog/setting-properties-for-wix-in-msbuild/

回答by Chris Kaczor

I did this in one of my projects by writing a preprocessor extension to read the file version from my executable. So the WiX file looks something like:

我在我的一个项目中通过编写预处理器扩展来从我的可执行文件中读取文件版本来做到这一点。所以 WiX 文件看起来像:

<?define ProductName="$(fileVersion.ProductName($(var.MyApp.TargetPath)))" ?>
<?define CompanyName="$(fileVersion.CompanyName($(var.MyApp.TargetPath)))" ?>
<?define ProductVersion="$(fileVersion.ProductVersion($(var.MyApp.TargetPath)))" ?>
<Product 
    Id="<product ID>" 
    Name="$(var.ProductName)" 
    Version="$(var.ProductVersion)" 
    Manufacturer="$(var.CompanyName)" 
    Language="1033" 
    UpgradeCode="<upgrade code>">

I've posted the code for in on CodePlex: http://wixfileversionext.codeplex.com/

我已经在 CodePlex 上发布了代码:http: //wixfileversionext.codeplex.com/

回答by Brock Hensley

Here's a very simple way to get your Bootstrapper Bundle Version to match your MyApp AssemblyVersion using a BeforeBuild Targetand DefineConstants.

这里是一个非常简单的方法,让你的引导程序版本捆绑使用,以配合您的MyApp的的AssemblyVersionBeforeBuild TargetDefineConstants

Bundle.wxs:

捆绑.wxs:

<Bundle Name="$(var.ProductName) Bootstrapper v$(var.BuildVersion)"
     Version="$(var.BuildVersion)"

Bootstrapper.wixproj:

Bootstrapper.wixproj:

<Target Name="BeforeBuild">
  <GetAssemblyIdentity AssemblyFiles="..\MyApp\bin$(Configuration)\MyApp.exe">
    <Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
  </GetAssemblyIdentity>
  <PropertyGroup>
    <DefineConstants>BuildVersion=%(AssemblyVersion.Version)</DefineConstants>
  </PropertyGroup>
</Target>

回答by K0D4

In case someone is looking for an actual XML example, this works with .NET assemblies (and you don't have to do the Assembly or KeyPath attributes). I eliminated unrelated code with [...] place holders:

如果有人正在寻找实际的 XML 示例,这适用于 .NET 程序集(并且您不必执行 Assembly 或 KeyPath 属性)。我用 [...] 占位符删除了不相关的代码:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product [...] Version="!(bind.fileVersion.MyDLL)">
        [...]
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder" Name="PFiles">
                <Directory Id="INSTALLDIR" Name="MyDLLInstallLocation">
                    <Component Id="MainLib" Guid="[...]">
                        <File Id="MyDLL" Name="MyDll.dll" Source="MyDll.dll" />
                        [...]
                    </Component>
                    [...]
                </Directory>
            </Directory>
        </Directory>
    </Product>
</Wix>

回答by Edward Brey

You can pass the version to the MSBuild script for your setup project the same as you can pass for application's build script.

您可以将版本传递给安装项目的 MSBuild 脚本,就像传递应用程序的构建脚本一样。

For example, if your CI system defines variables AppVersionand BuildNumber, and passes them to your MSBuild scripts, your wixproj can create a corresponding Versionproperty which it forwards to Wix like this:

例如,如果您的 CI 系统定义了变量AppVersionand BuildNumber,并将它们传递给您的 MSBuild 脚本,您的 wixproj 可以创建一个相应的Version属性,它会像这样转发给 Wix:

<PropertyGroup>
    <Version Condition=" '$(BuildNumber)' == '' ">0.0.1</Version>
    <Version Condition=" '$(BuildNumber)' != '' ">$(AppVersion).$(BuildNumber)</Version>
    <DefineConstants>Version=$(Version)</DefineConstants>
</PropertyGroup>

The first definition of Versionprovides a default for when you're building locally. Whatever it ends up with becomes a Versionvariable in Wix. Use it in a wsx file like this:

第一个定义Version为您在本地构建时提供了默认值。无论最终结果如何,都将成为VersionWix 中的一个变量。在 wsx 文件中使用它,如下所示:

<Product Version="$(var.Version)" ...>
    <Package Description="$(var.ProductName) $(var.Version): $(var.ProductDescription)" ... />

I like to include the version in the description so that it's easy to look up from Window Explorer (as a column in Detail view or on the Properties page) independent of the file name.

我喜欢在描述中包含版本,以便可以很容易地从 Window Explorer(作为详细信息视图或属性页面中的列)独立于文件名进行查找。

Passing the version as a variable gives you more control than reading it from a file. When you read from a file, you get all 4 parts of the programmatic version. However, ProductVersionis only designed to use the first 3 parts.

将版本作为变量传递给你比从文件中读取它更多的控制。当您从文件中读取时,您将获得程序化版本的所有 4 个部分。但是,ProductVersion仅设计为使用前 3 个部分。