使用 Wix 工具包在 Azure DevOps 中构建 MSI

Build MSI in Azure DevOps using Wix Toolkit

我有一个包含两个项目的 Visual Studio 解决方案; MyProject 和 MyProject.Installer,其中后者是 Wix 工具集项目。我从Wix项目中引用MyProject,因为我不想要典型的构建输出,而是独立的二进制文件(见管道)。

我做了一个 dotnet 发布并输出我想要的文件到 \client 相对于 MyProject.Installer wix 项目。在 Product.wxs 文件中,我引用了这些文件:

<Component Id="MyProject.exe" Guid="b1211231-2e88-4679-b2d3-879e8a3f9353">
    <File Id="MyProject.exe" Source="client\MyProject.exe" KeyPath="yes"  />
</Component>

我的 Azure DevOps 管道如下:

trigger:
- master

pool:
  vmImage: 'windows-latest'
variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
steps:
- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'
- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: false
    projects: '**/MyProject.csproj'
    arguments: '--output $(Build.ArtifactStagingDirectory)\client --configuration $(BuildConfiguration) --runtime win-x86 -p:PublishSingleFile=true -p:PublishTrimmed=true'
    zipAfterPublish: false
    modifyOutputPath: false
- task: MSBuild@1
  inputs:
    solution: '**/*.wixproj'
    configuration: '$(BuildConfiguration)'
    msbuildArguments: '/p:RunWixToolsOutOfProc=true'
- task: PublishBuildArtifacts@1
  displayName: 'Save artifacts'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

管道输出运行(成功):

"C:\Program Files\dotnet\dotnet.exe" publish D:\a\s\MyProject\MyProject.csproj --output D:\a\a\client --configuration Release --runtime win-x86 -p:PublishSingleFile=true -p:PublishTrimmed=true

和WIX(未成功):

C:\Program Files (x86)\WiX Toolset v3.11\bin\Light.exe -out D:\a\s\MyProject.Installer\bin\Release\nb-NO\MyProject.Installer.msi -pdbout D:\a\s\MyProject.Installer\bin\Release\nb-NO\MyProject.Installer.wixpdb -cultures:nb-NO -ext "C:\Program Files (x86)\WiX Toolset v3.11\bin\WixUIExtension.dll" -loc Product.nb-NO.wxl -contentsfile obj\Release\MyProject.Installer.wixproj.BindContentsFileListnb-NO.txt -outputsfile obj\Release\MyProject.Installer.wixproj.BindOutputsFileListnb-NO.txt -builtoutputsfile obj\Release\MyProject.Installer.wixproj.BindBuiltOutputsFileListnb-NO.txt -wixprojectfile D:\a\s\MyProject.Installer\MyProject.Installer.wixproj obj\Release\Product.wixobj
##[error]MyProject.Installer\Product.wxs(108,0): Error LGHT0103: The system cannot find the file 'client\MyProject.exe'.

很明显它找不到要嵌入到 MSI 中的文件,但我不知道如何继续。

非常感谢任何有关如何组织项目、输出和配置管道的建议。

我目前的解决方案:

一个 Azure DevOps Git 存储库,由一个解决方案和两个项目组成。

  • 我的客户
  • MyClient.Installer

MyClient 项目有一个 local 发布配置文件,用于将构建输出发布到 wix 项目。这是发布配置文件:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>Any CPU</Platform>
    <PublishDir>bin\Release\net5.0\publish\</PublishDir>
    <PublishProtocol>FileSystem</PublishProtocol>
    <TargetFramework>net5.0</TargetFramework>
    <SelfContained>true</SelfContained>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <RuntimeIdentifier>win-x86</RuntimeIdentifier>
    <ProjectGuid>xxxx-xxxx-xxxx</ProjectGuid>
    <publishUrl>..\MyClient.Installer\Client</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <PublishSingleFile>True</PublishSingleFile>
    <PublishTrimmed>False</PublishTrimmed>
  </PropertyGroup>
</Project>

这样我可以在构建WIX项目时引用这些文件。

我在 Azure DevOps 中的构建管道:

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'
- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: false
    projects: '**/MyClient.csproj'
    arguments: '--output $(Build.ArtifactStagingDirectory)\client --configuration $(BuildConfiguration) --runtime win-x86 -p:PublishSingleFile=true -p:PublishTrimmed=true'
    zipAfterPublish: false
    modifyOutputPath: false
- task: CopyFiles@2
  inputs:
    SourceFolder: 'MyClient.Installer'
    Contents: '**'
    TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
  displayName: 'Save artifacts'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

这里我发布文件,我把WIX工程也复制到artifact文件夹下。现在工件包含 wix 项目和发布的输出 - 保存到 \client 文件夹,就像在本地一样。

有了可用的工件,我现在可以为不同的环境创建单独的 MSI,在构建 MSI 之前添加配置转换。