桌面应用程序的 ci/cd 过程与网站有一些差异,因为桌面应用程序的“部署”只是将安装包分发到目标位置,无需上架到应用商店。根据公司的管理流程,这个过程可以非常复杂,也可以非常简单。在简单的情况下,azure pipelines 中一个 wpf 桌面应用程序的 ci/cd 过程如下:
触发器启动 Pipeline 构建 WPF 应用程序 启动单元测试以确保构建质量 创建安装包 将安装包复制到目标位置 通知用户新安装包已经可以获取
在“使用 Azure Pipelines 实现 CI”这篇文章中,我已经讲解了如何实现第 1、2、3、5 步。至于第 6 步,可以在 Project Settings 的 Notifications 页面中设置使用邮件通知团队成员,也可以参考“使用连接器接收Azure DevOps的通知”这篇文章,通过 Teams 发送构建的结果。
现在我们还缺少第 4 步“创建安装包”,本文将介绍如何在 Azure Pipelines 中使用 Inno Setup 创建安装包。
![[Azure DevOps] 使用 Inno Setup 制作桌面软件安装包](https://img.php.cn/upload/article/001/503/042/175867399566203.jpg)
假设我们已经根据“使用 Azure Pipelines 实现 CI”的方法发布了一个 WPF 应用程序,发布到 Artifacts 的文件如上图所示,可以以 Zip 的形式将所有输出文件下载到本地,基本相当于绿色版软件。但我们不能将这个 Zip 包直接发给客户,我们至少还要包括开始菜单和修改注册表等一大堆东西,因此需要将 Release 的文件打包到一个安装包中。我的公司通常使用 Inno Setup 制作安装包,在 Azure Pipelines 中使用 Inno Setup 也非常简单,因此本文将使用 Inno Setup 作为制作安装包的例子。
首先我们需要一个 iss 脚本。在 install 目录下创建一个简单的名为 SetupScript.iss 的脚本文件,大部分保留了默认值(懒得修改公司名之类的了),它只是将 Release 目录的内容全部打包起来,内容如下:
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
<h1>define MyAppName "My Program"</h1><h1>define MyAppPublisher "My Company, Inc."</h1><h1>define MyAppURL "<a href="https://www.php.cn/link/4c74744a9c10b3001a1d9b87f86eb26f">https://www.php.cn/link/4c74744a9c10b3001a1d9b87f86eb26f</a>"</h1><h1>define MyAppExeName "wpf.exe"</h1><h1>define VersionSourceAssemblyName MyAppExeName</h1><h1>define BuildOutputFolder "..\wpf\bin\Release\"</h1><h1>define MyAppFileVersion GetFileVersion(AddBackslash(BuildOutputFolder) + VersionSourceAssemblyName)</h1><h1>define MyAppCustomerVersion GetStringFileInfo(AddBackslash(BuildOutputFolder) + VersionSourceAssemblyName, "ProductVersion")</h1><p>[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{0B50DAF7-728E-48C7-984F-5E6FDB924490}
AppName={#MyAppName}
AppVersion={#MyAppCustomerVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}{#MyAppName}
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputBaseFilename=mysetup {#MyAppCustomerVersion}
Compression=lzma
SolidCompression=yes
WizardStyle=modern
VersionInfoCompany={#MyAppPublisher}
VersionInfoVersion={#MyAppFileVersion}
VersionInfoProductName={#MyAppName}
VersionInfoProductTextVersion={#MyAppCustomerVersion}</p><p>[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"</p><p>[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked</p><p>[Files]
Source: "{#BuildOutputFolder}{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#BuildOutputFolder}*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files</p><p>[Icons]
Name: "{autoprograms}{#MyAppName}"; Filename: "{app}{#MyAppExeName}"
Name: "{autodesktop}{#MyAppName}"; Filename: "{app}{#MyAppExeName}"; Tasks: desktopicon</p><p>[Run]
Filename: "{app}{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent用 Inno Setup 运行一下这个脚本文件,确保它正确运行(如果成功的话会在 Installer\Output 目录下生成一个安装程序)。
将 SetupScript.iss 推送到 Azure Repos 上,然后修改对应的 Pipeline。Pipeline 中需要添加两个任务:
然后修改 CopyFiles 任务,将 Installer\output 目录中的安装包复制到 $(build.artifactstagingdirectory)。修改后的 YAML 文件如下(其中两个 PowerShell 任务即为新增的两个任务):
trigger:</p><ul><li>master</li></ul><p>pool: vmImage: 'windows-latest'</p><p>variables: solution: '*<em>/</em>.sln' buildPlatform: 'Any CPU' buildConfiguration: 'Release'</p><p>steps:</p><ul><li><p>task: NuGetToolInstaller@1</p></li><li><p>task: PowerShell@2 displayName: 'Inno setup download' inputs: targetType: 'inline' script: 'choco install innosetup'</p></li><li><p>task: NuGetCommand@2 inputs: restoreSolution: '$(solution)'</p></li><li><p>task: VSBuild@1 inputs: solution: '$(solution)' platform: '$(buildPlatform)' configuration: '$(buildConfiguration)'</p></li><li><p>task: PowerShell@2 displayName: 'Execute Inno Setup script' inputs: targetType: 'inline' script: 'iscc.exe Installer\SetupScript.iss'</p></li><li><p>task: CopyFiles@2 inputs: SourceFolder: 'Installer\output' Contents: '*.exe' TargetFolder: '$(build.artifactstagingdirectory)'</p></li><li><p>task: PublishBuildArtifacts@1 inputs: PathtoPublish: '$(Build.ArtifactStagingDirectory)' ArtifactName: 'drop' publishLocation: 'Container'
现在,一个桌面应用程序的 CI/CD 已经基本完成了。当然,实际应用中 iss 脚本和 PowerShell 都可以更复杂,以便完成更多任务,例如程序签名、检查并安装 .Net Framework 等,这些操作都超出了本文的范畴,如有需要可以参考以下链接:
以上就是[Azure DevOps] 使用 Inno Setup 制作桌面软件安装包的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号