简体   繁体   English

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

[英]Build MSI in Azure DevOps using Wix Toolkit

I have a Visual Studio solution consisting of two projects;我有一个由两个项目组成的 Visual Studio 解决方案; MyProject and MyProject.Installer where the latter is a Wix Toolset project. MyProject 和 MyProject.Installer,其中后者是一个 Wix 工具集项目。 I do not reference MyProject from the Wix project because I do not want the typical build output, but rather the stand-alone binaries (see pipeline).引用 Wix 项目中的 MyProject,因为我不想要典型的构建 output,而是独立的二进制文件(参见管道)。

I do a do.net publish and output the files I want to \client relative to the MyProject.Installer wix project.我做了一个 do.net 发布和 output 我想要 \client 相对于 MyProject.Installer wix 项目的文件。 In the Product.wxs file i reference these files:在 Product.wxs 文件中,我引用了这些文件:

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

My Azure DevOps pipeline is as follows:我的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'

Output from pipeline run (successful): Output 来自管道运行(成功):

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

And WIX (unsuccessful):和 WIX(未成功):

C:\Program Files (x86)\WiX Toolset v3.11\bin\Light.exe -out D:\a\1\s\MyProject.Installer\bin\Release\nb-NO\MyProject.Installer.msi -pdbout D:\a\1\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\1\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'.

It's clear that it cannot find the file to embed into the MSI, but I'm at a loss as to how to proceed.很明显,它找不到要嵌入到 MSI 中的文件,但我不知道如何继续。

Any advice on how to organize the projects, the output and configuring the pipeline is much appreciated.非常感谢有关如何组织项目、output 和配置管道的任何建议。

I have a Visual Studio solution consisting of two projects;我有一个由两个项目组成的 Visual Studio 解决方案; MyProject and MyProject.Installer where the latter is a Wix Toolset project. MyProject 和 MyProject.Installer,其中后者是 Wix 工具集项目。 I do not reference MyProject from the Wix project because I do not want the typical build output, but rather the stand-alone binaries (see pipeline).从 Wix 项目中引用 MyProject,因为我不想要典型的构建 output,而是独立的二进制文件(参见管道)。

I do a dotnet publish and output the files I want to \client relative to the MyProject.Installer wix project.我做了一个 dotnet 发布和 output 文件,我想要 \client 相对于 MyProject.Installer wix 项目。 In the Product.wxs file i reference these files:在 Product.wxs 文件中,我引用了这些文件:

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

My Azure DevOps pipeline is as follows:我的 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'

Output from pipeline run (successful): Output 从管道运行(成功):

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

And WIX (unsuccessful):和 WIX(不成功):

C:\Program Files (x86)\WiX Toolset v3.11\bin\Light.exe -out D:\a\1\s\MyProject.Installer\bin\Release\nb-NO\MyProject.Installer.msi -pdbout D:\a\1\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\1\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'.

It's clear that it cannot find the file to embed into the MSI, but I'm at a loss as to how to proceed.很明显,它找不到要嵌入 MSI 的文件,但我不知道如何继续。

Any advice on how to organize the projects, the output and configuring the pipeline is much appreciated.非常感谢有关如何组织项目、output 和配置管道的任何建议。

My current solution:我目前的解决方案:

A Azure DevOps Git Repository consisting of one solution with two projects.一个 Azure DevOps Git 存储库,由一个解决方案和两个项目组成。

  • MyClient我的客户
  • MyClient.Installer我的客户端.安装程序

The MyClient project has a local publish profile that publishes the build output to the wix project. MyClient 项目有一个本地发布配置文件,它将构建 output 发布到wix项目。 This is the publish profile:这是发布配置文件:

<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>

This way I can reference the files when building the WIX project.这样我就可以在构建 WIX 项目时引用这些文件。

My build pipeline in Azure DevOps:我在 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'

Here I publish the files, and I copy the WIX project to the artifact folder as well.我在这里发布文件,并将 WIX 项目也复制到 artifact 文件夹中。 Now the artifact contains the wix project and the published output - which is saved to the \client folder, just as it was locally.现在工件包含 wix 项目和已发布的 output - 保存到\client文件夹,就像在本地一样。

Having the artifact available I can now create separate MSI's for different environments, adding config transformations prior to building the MSI's.有了可用的工件,我现在可以为不同的环境创建单独的 MSI,在构建 MSI 之前添加配置转换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM