【问题标题】:Error MSB3325: Cannot import the following key file错误 MSB3325:无法导入以下密钥文件
【发布时间】:2019-12-19 01:34:11
【问题描述】:

我在 Azure DevOps 中托管了一个项目,但构建失败并显示错误消息:

错误 MSB3325:无法导入以下密钥文件:xxxx.pfx。钥匙 文件可能受密码保护。要更正此问题,请尝试导入 再次证书或手动将证书安装到 Strong 使用以下密钥容器名称命名 CSP:VS_KEY_xxxx

这发生在更改项目以使用新生成的受密码保护的 pfx 签名证书对程序集进行签名之后。

我尝试了其他 SO 帖子中给出的各种修复,但似乎没有任何效果。

任何具有 azure-devops 专业知识的人都可以帮助我解决这种情况吗?

【问题讨论】:

    标签: msbuild azure-devops assembly-signing


    【解决方案1】:

    您可以使用 SnInstallPfx.exe 并将其作为 powershell 任务添加到您的管道中

    - task: PowerShell@2
      env:
        SN_INSTALL_PFX: $(snInstallPfx.secureFilePath)
        MYCERTIFICATE_PFX: $(myCertificatePfx.secureFilePath)
        MYCERTIFICATE_PFX_PASSWORD: $(myCertificatePfxPassword)
      inputs:
        targetType: 'inline'
        script: '&"$($ENV:SN_INSTALL_PFX)" "$($ENV:MYCERTIFICATE_PFX)" "$($ENV:MYCERTIFICATE_PFX_PASSWORD)"'
    

    pfx、exe 和密码作为安全文件和变量存储在 Pipeline 库中。

    更多信息,请参阅以下blog article

    【讨论】:

      【解决方案2】:

      错误 MSB3325:无法导入以下密钥文件

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

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

      它在我这边工作得很好。

      您可以查看similar thread 了解更多详情。

      希望这会有所帮助。

      【讨论】:

      • 我尝试了上面的脚本,但它不起作用。 -argumentlist "MY" 应该是什么?
      • -argumentlist "MY" 应该是什么?我尝试使用构建错误中指定的密钥容器名称(类似于 VS_KEY_5FC03B158F74XXXX),但没有成功。
      猜你喜欢
      • 2013-02-12
      • 1970-01-01
      • 2013-02-23
      • 2018-10-08
      • 2015-07-21
      • 2017-03-23
      • 2011-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多