题
我编写了一个应用程序及其WiX安装程序,并使用subversion将其置于版本控制之下。当WiX安装程序构建时,我希望其版本号是应用程序的当前构建版本。我该如何做到这一点?我使用c#来编写应用程序。
N.B。我正在使用ccnet来构建这个项目
解决方案
您可以使用Product / @ Version ="!(bind.FileVersion.FileId)" (将 FileId
替换为您希望从中获取版本号的文件的 Id
),light.exe将使用引用的文件版本填充该值通过 FileId
。
其他提示
我在我的一个项目中通过编写预处理器扩展来从我的可执行文件中读取文件版本。所以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>">
我已在CodePlex上发布了代码: http://wixfileversionext.codeplex.com/
如果有人正在寻找一个实际的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>
这是使用 BeforeBuild Target
和 DefineConstants
让您的Bootstrapper Bundle版本与MyApp AssemblyVersion匹配的一种非常简单的方法。
Bundle.wxs:
<Bundle Name="$(var.ProductName) Bootstrapper v$(var.BuildVersion)"
Version="$(var.BuildVersion)"
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>
这看起来非常接近你想要完成的事情。查看巡航控制中的等效物。
您可以将版本传递给安装项目的MSBuild脚本,就像传递应用程序的构建脚本一样。
例如,如果您的CI系统定义了变量 AppVersion
和 BuildNumber
,并将它们传递给您的MSBuild脚本,那么您的wixproj可以创建相应的 Version 代码>属性,它转发给Wix像这样:
<PropertyGroup>
<Version Condition=" '$(BuildNumber)' == '' ">0.0.1</Version>
<Version Condition=" '$(BuildNumber)' != '' ">$(AppVersion).$(BuildNumber)</Version>
<DefineConstants>Version=$(Version)</DefineConstants>
</PropertyGroup>
Version
的第一个定义提供了在本地构建时的默认值。无论它最终成为Wix中的 Version
变量。在像这样的wsx文件中使用它:
<Product Version="$(var.Version)" ...>
<Package Description="$(var.ProductName) $(var.Version): $(var.ProductDescription)" ... />
我喜欢在描述中包含该版本,以便可以从Window Explorer(作为详细视图中的列或属性页面)查找,而与文件名无关。
将版本作为变量传递给您比从文件中读取更多的控制权。当您从文件中读取时,您将获得程序化版本的所有4个部分。但是, ProductVersion 仅用于前3个部分