我最后做了什么:
在我的 WiX 设置项目中,在myproject.wixproj
MSBuild 文件中,我添加了一个新的自定义任务,如下所示:
<UsingTask TaskName="GetThreePartVersion" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<AssemblyPath ParameterType="System.String" Required="true" />
<ThreePartVersion ParameterType="System.String" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.Diagnostics" />
<Code Type="Fragment" Language="cs">
<![CDATA[
Log.LogMessage("Getting version details of assembly at: " + this.AssemblyPath, MessageImportance.High);
Version v = Version.Parse(FileVersionInfo.GetVersionInfo(this.AssemblyPath).FileVersion);
this.ThreePartVersion = v.ToString(3);
]]>
</Code>
</Task>
</UsingTask>
然后在BeforeBuild
目标中,我添加了这些行来调用此任务并使用结果定义一个 WiX 常量:
<Target Name="BeforeBuild">
<GetThreePartVersion AssemblyPath="$(SolutionDir)Plugin\$(OutputPath)Swisscom.Vidia.Plugin.dll">
<Output TaskParameter="ThreePartVersion" PropertyName="ThreePartVersionNumber" />
</GetThreePartVersion>
<PropertyGroup>
<DefineConstants>ThreePartBuildVersion=$(ThreePartVersionNumber)</DefineConstants>
</PropertyGroup>
<Message Text="Three-part version: $(ThreePartVersionNumber)" />
</Target>
现在在我的 WiXproject.wxs
文件中,我可以引用已定义的常量,并将其用于<Product Version="..." ... />
属性:
<Product Id="*" Name="MyProject" Language="1033"
Version="$(var.ThreePartBuildVersion)" ......>
在我最终做对之前,我花了一些时间和大量的试验和错误,但这就是它现在对我有用的方式。希望有一天这可能会帮助其他人......