我编写了一个应用程序和它的WiX安装程序,并使用Subversion将其置于版本控制下。当WiX安装程序构建时,我希望它的版本号是应用程序的当前构建版本。我该如何实现这一点?我使用c#编写了应用程序。
注:我正在使用ccnet来构建此项目
Product/@Version="!(bind.FileVersion.FileId)"
(将FileId
替换为您想要获取版本号的文件的Id
),然后light.exe将使用所引用的FileId
文件的版本填充该值。请参阅WiX v3文档以获取所有可用变量。如果有人正在寻找一个真实的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>
!(bind.fileVersion.MyDLL)
,它使用第三部分来引用<File Id="MyDLL"...
部分。 - K0D4我在我的一个项目中通过编写预处理器扩展来读取可执行文件的文件版本来实现了这一点。因此,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/
<?define ProductName="!(bind.property.ProductName)" ?><?define CompanyName="!(bind.property.Manufacturer)" ?><?define ProductVersion=!(bind.FileVersion.FileId) ?>
让它工作了。其中 FileId
是 Component
内的一个 File
元素的 Id
属性的值。 - Jesus is Lord使用 BeforeBuild Target
和 DefineConstants
,可以非常简单地使您的 Bootstrapper Bundle 版本与 MyApp AssemblyVersion 匹配。
Bundle.wxs:
<Bundle Name="$(var.ProductName) Bootstrapper v$(var.BuildVersion)"
Version="$(var.BuildVersion)"
引导程序.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>
<Bundle>
上方定义了你的 var.ProductName
和 var.BuildVersion
变量? - Brock HensleyBeforeBuild
目标,因此有必要明确指定 AfterTargets="AfterResolveReferences"
。 - Dmitry<Target Name="CustomBeforeBuild" BeforeTargets="BeforeBuild">
从一个EXE文件中获取版本对我来说不起作用,只有DLL文件可以。 - undefined<PropertyGroup>
<Version Condition=" '$(BuildNumber)' == '' ">0.0.1</Version>
<Version Condition=" '$(BuildNumber)' != '' ">$(AppVersion).$(BuildNumber)</Version>
<DefineConstants>Version=$(Version)</DefineConstants>
</PropertyGroup>
版本
的第一个定义为在本地构建时提供默认值。无论最终结果是什么,都会成为Wix中的版本
变量。可以在wsx文件中像这样使用它:
<Product Version="$(var.Version)" ...>
<Package Description="$(var.ProductName) $(var.Version): $(var.ProductDescription)" ... />
<Version Condition=" '$(BuildVersionOfAsm)' != '' ">$(BuildVersionOfAsm)</Version>
,其中BuildVersionOfAsm是devops管道中的一个变量。 - Robetto<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>0.1.0</Version>
</PropertyGroup>
</Project>
.wixproj
中获取版本并定义一个常量<Project Sdk="WixToolset.Sdk/4.0.0">
<PropertyGroup>
<OutputName>Example_MSI_name_v$(Version)_$(RuntimeIdentifier)</OutputName>
<DefineConstants>
ProductVersion=$(Version);
</DefineConstants>
</PropertyGroup>
</Project>
.wxs
文件中,定义了软件包设置。<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
<Package ProductCode="*"
UpgradeCode="$(var.UpgradeCode)"
Name="!(loc.ProductName)"
Language="!(loc.Language)"
Version="$(var.ProductVersion)"
Manufacturer="!(loc.Company)">
[...]
</Package>
</Wix>