在Azure DevOps中创建.appinstaller:SFTP本地安装方案问询
解决方案:SFTP环境下的MSIX本地更新配置
核心需求
- 基于WPF应用构建MSIX包,通过Azure DevOps CI/CD推送到SFTP服务器
- 不依赖公共URI,通过本地下载
.appinstaller文件完成应用安装与更新
可行方案
方案1:将SFTP映射为本地网络驱动器
借助WinFsp+SSHFS工具,把SFTP服务器映射成Windows本地网络驱动器(例如Z:\),这样就能用本地路径格式配置.appinstaller的更新源:
- 在用户部署机器上完成SFTP到网络驱动器的映射
- 配置
.appinstaller时,将uri和mainItemUri设为映射后的驱动器路径(如Z:\MSIXPackages) - 优势:完全复用现有
.appinstaller的本地更新逻辑,无需修改包结构
方案2:CI/CD流程中修改.appinstaller路径
Azure DevOps生成的.appinstaller是XML格式,可在流水线中新增步骤替换更新源为本地路径:
- 在
AppInstallerFile@1任务后添加PowerShell脚本,修改XML中的Uri节点 - 示例脚本:
$appInstallerPath = "$(Build.ArtifactStagingDirectory)/$(Build.BuildNumber).appinstaller" $xml = [xml](Get-Content $appInstallerPath) # 设置为相对路径,用户下载后将包和.appinstaller放在同一目录即可 $xml.AppInstaller.MainPackage.Uri = "$(Build.BuildNumber).msix" $xml.Save($appInstallerPath)
- 将修改后的
.appinstaller和MSIX包一同推送到SFTP,用户下载到本地同目录即可安装更新
方案3:内网文件共享中转
如果SFTP服务器可接入企业内网,可搭建本地文件共享目录作为中转:
- CI/CD先将MSIX包和
.appinstaller推送到内网共享目录 - 再同步到SFTP服务器
- 用户下载
.appinstaller后,更新源指向内网共享路径(如\\InternalServer\MSIXRepo),实现内网环境下的自动更新
调整后的Azure DevOps YAML示例
- task: MsixPackaging@1 inputs: outputPath: '$(Build.ArtifactStagingDirectory)/$(Build.BuildNumber).msix' solution: 'app.sln' clean: true generateBundle: true buildConfiguration: 'release' buildForX86: false updateAppVersion: false appPackageDistributionMode: 'SideloadOnly' msbuildLocationMethod: 'version' msbuildVersion: 'latest' msbuildArchitecture: 'x64' - task: AppInstallerFile@1 displayName: 'Create AppInstaller' inputs: package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildNumber).msix' outputPath: '$(Build.ArtifactStagingDirectory)/$(Build.BuildNumber).appinstaller' uri: '.' # 临时设为相对路径占位符 mainItemUri: '.' showPromptWhenUpdating: true updateBlocksActivation: true # 新增步骤:修改AppInstaller为本地相对路径 - task: PowerShell@2 displayName: 'Update AppInstaller Local Path' inputs: targetType: 'inline' script: | $appInstallerPath = "$(Build.ArtifactStagingDirectory)/$(Build.BuildNumber).appinstaller" $xml = [xml](Get-Content $appInstallerPath) $xml.AppInstaller.MainPackage.Uri = "$(Build.BuildNumber).msix" $xml.Save($appInstallerPath) # 推送到SFTP服务器任务 - task: SftpUpload@1 inputs: sshEndpoint: 'YourSFTPConnection' sourceFolder: '$(Build.ArtifactStagingDirectory)' contents: | **/*.msix **/*.appinstaller targetFolder: '/MSIXUpdates' cleanTargetFolder: false preserveTimestamp: true
关键注意事项
- 建议用相对路径配置
.appinstaller,确保用户将MSIX包和.appinstaller放在同一本地目录即可识别 - 旁加载模式下,需确保用户机器已开启允许旁加载应用的系统设置
- 若使用网络驱动器映射,需保证用户机器已挂载对应SFTP驱动器且有读写权限
内容的提问来源于stack exchange,提问作者Damien Bafile
相关产品推荐
相关产品推荐

