问题描述
我们已为客户端 Microsoft Office 扩展程序开发,它们确实需要代码签名。
为了开发,我在 VS -> 项目属性 -> 签名 -> 创建测试证书中做了一个 .pfx
。输入空密码,将 .pfx
转储到源代码管理中,并在开发时为整个公司构建。
对于插件的发布,情况有所不同,我们需要与客户端 .pfx
签署一个扩展,并且他们希望在 Azure DevOps 中添加一个步骤来自动构建管道。问题是他们不能使用 cloud solutions,所以据我所知 Azure Key Vault 不在图片中。他们确实有一台本地可信机器,我们可以将他们的 .pfx
用于签名。
我找不到如何在 Azure Pipelines 中进行签名的方法,这不涉及 Azure Key Vault 或 Azure Secure Files,但我希望有一种机制可以实现这一点,因为它看起来很常见的事情。
在 Azure Devops Pipelines 中使用本地机器对 .pfx 签名代码的首选解决方案是什么?
解决方法
我们最终得到了以下结果:
在本地构建机器上添加了 .pfx
。
向 Azure 构建管道添加了隐藏变量 pfxPassword
然后添加以下构建步骤 tp Azure 构建管道:
trigger:
- main
pool:
name: 'XXX Build Pool'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
#change to actual directory where signtool is.
pathToSignTool: "\"C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.19041.0\\x64\\signtool.exe\""
pathToPfx: "C:\\XXX\\Install\\XXX_Applications.pfx"
pathToBuildDirectory: "\\XXXYYY\\bin\\Release\\"
pathToMageTool: "\"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v10.0A\\bin\\NETFX 4.8 Tools\\mage.exe\""
pathToContinousDeployment: "C:\\ContinousDeployment\\YYY\\"
name: $(MajorVersion).$(MinorVersion).$(date:yy)$(DayOfYear)$(rev:.r)
steps:
- task: Assembly-Info-NetFramework@2
inputs:
Path: '$(Build.SourcesDirectory)'
FileNames: |
**\AssemblyInfo.cs
InsertAttributes: true
FileEncoding: 'auto'
WriteBOM: false
VersionNumber: '$(Build.BuildNumber)'
FileVersionNumber: '$(Build.BuildNumber)'
InformationalVersion: '$(Build.BuildNumber)'
LogLevel: 'verbose'
FailOnWarning: false
DisableTelemetry: false
- task: VSBuild@1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- script:
$(pathToMageTool) -s $(Build.Repository.LocalPath)$(pathToBuildDirectory)XXXYYY.vsto -cf $(pathToPfx) -pwd %MAPPEDPASS%
env:
MAPPEDPASS: $(pfxPassword)
- script:
$(pathToMageTool) -s $(Build.Repository.LocalPath)$(pathToBuildDirectory)XXXYYY.dll.manifest -cf $(pathToPfx) -pwd %MAPPEDPASS%
env:
MAPPEDPASS: $(pfxPassword)
- script:
$(pathToSignTool) sign /f $(pathToPfx) /p %MAPPEDPASS% $(Build.Repository.LocalPath)$(pathToBuildDirectory)XXXYYY.dll
env:
MAPPEDPASS: $(pfxPassword)
- task: CopyFiles@2
inputs:
SourceFolder: '$(Build.Repository.LocalPath)$(pathToBuildDirectory)'
Contents: '**'
TargetFolder: '$(pathToContinousDeployment)'
OverWrite: true