Visual Studio团队服务部署/构建证书错误

时间:2017-04-21 16:02:34

标签: azure-devops azure-pipelines azure-pipelines-build-task

我正在尝试使用VSTS中的持续集成和部署功能构建一次性点击应用程序(Visual Studio团队服务在线)我们正在尝试使用Hosted代理构建此Visual Studio 2015我们在签署强名称密钥时遇到了困难错误为

的文件

MSB3326: Cannot import the following key file: xxxx.snk. The key file may be password protected. To correct this, try to import the certificate again or import the certificate manually into the current user's personal certificate store. 之后

MSB3321: Importing key file "xxxx.pfx" was canceled.

我试图从商店和文件中选择更改位置并确保提交但没有成功。 任何想法我如何克服这些错误或做错了什么。

选择回答的补充

只是想澄清是否有其他人有同样的问题,除了答案我必须将我的证书放在我的源代码管理代码中并提交它。然后选择其位置在VSTS Build

上添加一个全局变量

enter image description here

$cert.Import("$(CertPath)", $password, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]"PersistKeySet") 其中$(CertPath)类似于$(Build.SourcesDirectory)\SharedSolutionFiles\CertificateName.pfx

3 个答案:

答案 0 :(得分:6)

您可以在构建定义中创建PowerShell脚本并添加PowerShell脚本步骤,以便在VSBuild步骤之前导入证书文件。

在没有PowerShell导入证书的情况下构建失败步骤: enter image description here

使用PowerShell导入证书传递构建步骤: enter image description here

我使用的PowerShell脚本:

$pfxpath = 'pathtoees.pfx'
$password = 'password'

Add-Type -AssemblyName System.Security
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import($pfxpath, $password, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]"PersistKeySet")
$store = new-object system.security.cryptography.X509Certificates.X509Store -argumentlist "MY", CurrentUser
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]"ReadWrite")
$store.Add($cert)
$store.Close()

答案 1 :(得分:1)

更好的方法是,您可以设置on premise build agent并将证书导入证书存储区,然后将构建代理服务帐户更改为同一帐户。

答案 2 :(得分:0)

除了使用内部构建或将证书加载到构建代理上的证书存储上(这可能被认为是不安全的)外,还可以覆盖构建任务FileSign并构建使用证书文件和密码的构建任务

我在这里概述了步骤: https://stackoverflow.com/a/55313239/2068626