Visual studio 团队服务 deploymen/buildt 证书错误

Visual studio team services deploymen/buildt certificate error

我正在尝试使用 VSTS 中的持续集成和部署功能构建一个单击一次的应用程序(Visual studio 在线团队服务)我们正在尝试使用托管代理 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.

我已经尝试 select 从存储和从文件更改位置并确保提交但没有成功。 任何想法我可以如何克服这个错误或做错了什么。

对答案的澄清 selected

如果其他人有同样的问题,我只想澄清一下,除了答案之外,我还必须将我的证书放在我的源代码控制代码中并提交。然后到select它的位置在VSTS Build

上添加一个全局变量

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

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

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

没有 PowerShell 导入证书步骤,构建失败:

构建已通过 PowerShell 导入证书步骤:

我使用的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()

不使用本地构建或将证书加载到构建代理上的证书存储区(这可能被认为是不安全的),而是可以覆盖构建任务 FileSign 并构建一个使用证书文件的任务和密码。

我在这里概述了步骤: