WiX 工具集 v4:动态设置安装程序的目标/输出名称

问题描述 投票:0回答:1

将 WiX 安装程序项目 (.wixproj) 文件升级到 v4 后,项目中用于设置安装程序文件输出的 TargetName 的 MSBuild 步骤不再有效。

我想将要安装的应用程序的程序集版本动态附加到 msi 文件名的 TargetName,即

MyApplication.X.X.X.X.msi
.

下面是当前状态下的 .wixproj 文件的片段(为了简洁起见,我删除了一些代码):

<Project InitialTargets="SetVersion;BeforeBuild;CopyLinkedContentFiles">
  <Import Project="Sdk.props" Sdk="WixToolset.Sdk" Version="4.0.0-rc.1" />
  [...]
  <Target Name="SetVersion">
    <GetAssemblyIdentity AssemblyFiles="$(SolutionDir)\bin\$(Platform)\$(Configuration)\MyApp.exe">
      <Output TaskParameter="Assemblies" ItemName="Assembly" />
    </GetAssemblyIdentity>
    <CreateProperty Value="$(SolutionName).%(Assembly.Version)">
      <Output TaskParameter="Value" PropertyName="TargetName" />
    </CreateProperty>
    <PropertyGroup>
      <DefineConstants>BuildVersion=%(Assembly.Version)</DefineConstants>
    </PropertyGroup>
  </Target>
  <Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
    <Copy SourceFiles="%(Content.Identity)" DestinationFiles="%(Content.Link)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" Condition="'%(Content.Link)' != ''" />
  </Target>
  <Import Project="Sdk.targets" Sdk="WixToolset.Sdk" Version="4.0.0-rc.1" />
  [...]
</Project>

.wixproj 以前有以下代码来调整

TargetName

<Target Name="SetVersion">
        <PropertyGroup>
            <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
            <Platform Condition=" '$(Platform)' == '' ">x64</Platform>
            <SccProjectName>SAK</SccProjectName>
            <SccProvider>SAK</SccProvider>
            <SccAuxPath>SAK</SccAuxPath>
            <SccLocalPath>SAK</SccLocalPath>
            <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\OCS.Service\</SolutionDir>
        </PropertyGroup>
        <GetAssemblyIdentity AssemblyFiles="$(SolutionDir)\bin\$(Platform)\$(Configuration)\MyApp.exe">
            <Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
        </GetAssemblyIdentity>
        <PropertyGroup>
            <DefineConstants>BuildVersion=%(AssemblyVersion.Version)</DefineConstants>
        </PropertyGroup>
        <PropertyGroup>
            <TargetName>$(SolutionName).%(AssemblyVersion.Version)</TargetName>
        </PropertyGroup>
    </Target>

后一种解决方案在升级到 v4 之前按预期工作,但是,在构建项目并检查构建输出时,尚未应用对

TargetName
的更改。

wix wix4
1个回答
0
投票

我在 WiX 讨论网站 (https://github.com/orgs/wixtoolset/discussions/7317#discussioncomment-5445882) 上提出了问题,答案是 WiX4 不使用 TargetName 等

我采取了简单的方法并将 outputname 设置为已知值。构建完成后,我使用我想要的模式复制安装程序和它的 pdb,然后删除已知名称。

所以在wix4项目文件的顶部:

    <PropertyGroup>
        <OutputName>xyzzy</OutputName>
    </PropertyGroup>

在底部:

    <Import Project="Sdk.targets" Sdk="WixToolset.Sdk" Version="4.0.0-rc.4" />
    
    <Target Name="BeforeBuild">
        <!-- Get the programs assembly version from the .exe file -->
        <GetAssemblyIdentity AssemblyFiles="$(SolutionDir)SystemMonitorService.2012\$(OutputPath)SystemMonitorService.exe">
            <Output TaskParameter="Assemblies" ItemName="AsmInfo" />
        </GetAssemblyIdentity>
        <!-- Store the assembly version number in ProductVersion preprocessor variable -->
        <CreateProperty Value="$(DefineConstants);ProductVersion=%(AsmInfo.Version)">
            <Output TaskParameter="Value" PropertyName="DefineConstants" />
        </CreateProperty>
    </Target>
    
    <Target Name="AfterBuild" AfterTargets="Build">
        <!-- Name the .msi file after the solution configuration and assembly version e.g TestService-DebugAll-1.4.0.0.msi -->
        <CreateProperty Value="$(SolutionName)-$(Configuration)-%(AsmInfo.Version)">
            <Output TaskParameter="Value" PropertyName="NewOutputName" />
        </CreateProperty>
        <Copy SourceFiles="$(ProjectDir)bin\xyzzy.msi" DestinationFiles="$(ProjectDir)bin\$(NewOutputName).msi" />
        <Copy SourceFiles="$(ProjectDir)bin\xyzzy.wixpdb" DestinationFiles="$(ProjectDir)bin\$(NewOutputName).wixpdb" />
        <Delete Files="$(ProjectDir)bin\xyzzy.msi" />
        <Delete Files="$(ProjectDir)bin\xyzzy.wixpdb" />
    </Target>

这给了我我想要的“Optimiser.2012-Debug-2.125.0.0.msi”(和相应的wixpdb)输出

© www.soinside.com 2019 - 2024. All rights reserved.