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

2024-03-20

我正在尝试使用 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.

我尝试从存储和文件中选择更改位置并确保提交但没有成功。 我有什么想法可以克服这个错误或者做错了什么。

对所选答案的澄清

只是想澄清是否有其他人有同样的问题,除了答案之外,我还必须将我的证书放入我的源代码控制代码中并提交它。然后选择其位置,在 VSTS 构建上添加一个全局变量

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


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

Build failed without PowerShell Import Certificate Step: enter image description here

Build passed with PowerShell Import Certificate Step: 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()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Visual Studio 团队服务部署/构建证书错误 的相关文章

随机推荐