微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 Wix Toolkit 在 Azure DevOps 中构建 MSI

如何解决使用 Wix Toolkit 在 Azure DevOps 中构建 MSI

我有一个由两个项目组成的 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\1\s\MyProject\MyProject.csproj --output D:\a\1\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\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'.

很明显它找不到要嵌入 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 项目复制到工件文件夹中。现在工件包含 wix 项目和发布的输出 - 保存到 \client 文件夹,就像它在本地一样。

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。