VSTS 构建失败,MSB3325,无法导入 PFX 密钥文件 [英] VSTS build fails with MSB3325, Cannot import PFX key file

查看:11
本文介绍了VSTS 构建失败,MSB3325,无法导入 PFX 密钥文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个构建定义,用于在visualstudio.com 上在线构建一个桌面应用程序,该应用程序在任务构建解决方案(Visual Studio 构建)时失败并出现以下错误,

I had created a build definition to build a desktop application online on visualstudio.com which fail at task Build Solution (Visual Studio build) with following error,

[错误]C:Program Files (x86)Microsoft VisualStudio2017EnterpriseMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(3156,5):错误 MSB3325:无法导入以下密钥文件:Sixmod5Certificate.pfx.密钥文件可能受密码保护.到更正此问题,尝试再次导入证书或手动安装具有以下密钥的强名称 CSP 的证书容器名称:VS_KEY_3B2BCC84AE4E26F1

[error]C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild15.0BinMicrosoft.Common.CurrentVersion.targets(3156,5): Error MSB3325: Cannot import the following key file: Sixmod5Certificate.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_3B2BCC84AE4E26F1

我遵循了 https://developercommunity.visualstudio.com/content/problem/156086/vsts-build-msb3325-cannot-import-the-following-key.html

然后按照 https://stackoverflow.com/a/48698229/3531672 中的规定我在build任务之前加了一个powershell脚本任务,如下,

then as specified at, https://stackoverflow.com/a/48698229/3531672 I had added a powershell script task before build task, as follows,

[CmdletBinding()]
param(  
    [Parameter(Mandatory)][string] $pfxpath,
    [Parameter(Mandatory)][string] $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()

但还没有运气,

有类似于此指定解决方案的不同 SO 帖子,可从管理员用户构建,或手动安装 pfx 证书,但由于它们与个人计算机相关,我正在尝试在visualstudio.com 上配置持续集成,因此它们没有对我来说似乎很有用.

There are different SO post similar to this specifying solution to build from Admin user, or installing pfx certificate manually, but as they are related to personal computer and I am trying to configure Continuous integration on visualstudio.com, they don't seem useful to me.

请注意,我可以在本地机器上成功构建.

Please note I am able to successfully build on my local machine.

如果您希望最终重现此问题,请按照以下步骤操作,

If you wish to regenerate this problem at your end, follow these steps,

第 1 步:创建一个新的 VSTO 插件项目(任何 Excel/Word/Powerpoint).

STEP 1: Create a new VSTO Addin Project (Any Excel/Word/Powerpoint).

第 2 步:将此附加到 VSTS.

STEP 2: Attach this to VSTS.

第 3 步:在应用程序属性的签名选项卡中,不使用临时证书,而是创建一个新的受密码保护的证书(在我的情况下为 PFX - 个人信息交换)并使用它来签署 ClickOnce 清单

STEP 3: In signing tab of Application properties, instead of using temperory certificate, create a new password protected certificate (PFX - Personal Information Exchange in my case) and use this to sign ClickOnce Manifest

第 4 步:尝试在本地机器上构建,它会成功.

STEP 4: Try to build on local machine, it will succeed.

第 5 步:将其推过去并尝试在 VSTS 上构建,您将得到与上述相同的错误.

STEP 5: Push it over and try to build on VSTS, you will get the same error as above.

推荐答案

我从项目属性 -> 签名"页面取消选中对程序集签名"复选框,一切都像魅力一样工作.构建已通过 VSTS 成功签名.不知何故,我错过了与该问题相关的许多 SO 线程中提供的此解决方案.

I unchecked the "Sign the assembly" checkbox from the "project properties -> Signing" page and everything worked like a charm. The build was signed successfully through VSTS. Somehow I missed this solution provided in many SO threads related to the problem.

这篇关于VSTS 构建失败,MSB3325,无法导入 PFX 密钥文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆