【问题标题】:How to .pfx sign code using local machine in Azure Devops Pipelines?如何在 Azure Devops Pipelines 中使用本地计算机对代码进行 .pfx 签名?
【发布时间】:2021-09-19 00:52:27
【问题描述】:
我们为客户端开发了 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 签名代码的首选解决方案是什么?
【问题讨论】:
标签:
azure-devops
azure-pipelines
code-signing
office-addins
pfx
【解决方案1】:
我们最终得到以下结果:
在本地构建机器上添加了.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