VSTS构建失败,并显示MSB3325,无法导入PFX密钥文件

Ani*_*ali 5 msbuild azure-devops azure-pipelines-build-task azure-pipelines

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

[错误] C:\ Program Files(x86)\ Microsoft Visual Studio \ 2017 \ Enterprise \ MSBuild \ 15.0 \ Bin \ Microsoft.Common.CurrentVersion.targets(3156,5):错误MSB3325:无法导入以下密钥文件:Sixmod5Certificate .pfx。密钥文件可能受密码保护。若要更正此问题,请尝试再次导入证书或使用以下密钥容器名称将证书手动安装到“强名称” CSP:VS_KEY_3B2BCC84AE4E26F1

我遵循了https://developercommunity.visualstudio.com/content/problem/156086/vsts-build-msb3325-cannot-import-the-following-key.html中指定的解决方案

然后按照/sf/answers/3408876061/中的指定, 我在构建任务之前添加了一个powershell脚本任务,如下所示,

[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()
Run Code Online (Sandbox Code Playgroud)

但是还没有运气

有类似此指定解决方案的不同SO帖子,可以从Admin用户构建,也可以手动安装pfx证书,但是由于它们与个人计算机有关,并且我试图在visualstudio.com上配置持续集成,因此对于我。

请注意,我能够在本地计算机上成功构建。

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

步骤1:创建一个新的VSTO外接程序项目(任何Excel / Word / Powerpoint)。

步骤2:将此附加到VSTS。

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

步骤4:尝试在本地计算机上构建,它将成功。

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

Jab*_*bez 2

我从“项目属性 -> 签名”页面取消选中“对程序集进行签名”复选框,一切都非常顺利。构建已通过 VSTS 成功签名。不知怎的,我错过了许多与该问题相关的SO线程中提供的解决方案。