【问题标题】:Getting An error occurred while signing: Failed to sign file.exe. SignTool Error: No certificates were found that met all the given criteria签名时出错:无法对 file.exe 进行签名。 SignTool 错误:未找到满足所有给定条件的证书
【发布时间】:2017-09-13 14:33:04
【问题描述】:

好的 - 所以这真的很奇怪。我有一个签署文件的 TFS 版本,我收到了上面的消息。如果我查看构建中的日志,它会说它已成功签署并为我的文件加上时间戳(有一个手动调用 signtool 的 .proj 文件),但在不同的步骤中(不确定确切的位置) - 我假设它在ClickOnce 签名我得到错误。

我可以使用 Signtool 使用与构建使用相同的参数自己对文件进行签名,所以我想也许我需要导入他的证书,所以我打开了 mmc,添加了证书管理单元,完成了导入向导使用本地机器安装它(TFS 构建在与我不同的帐户下运行,我不知道该帐户的密码,所以我认为在机器级别安装它会起作用)。我浏览了该文件并将其成功导入受信任的根证书颁发机构(见下文):

我在构建时仍然遇到错误。从 TFS 构建中调用的 .proj 文件调用 signtool,然后在 ClickOnce 期间再次由构建调用。通过 VS 屏幕导入证书后,我现在看到:

并得到这个错误:

C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets (2718): Unable to find code signing certificate in the current user’s Windows certificate store. To correct this, either disable signing of the ClickOnce manifest or install the certificate into the certificate store.
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets (2718): Cannot import the following key file: . 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.
C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets (2718): Importing key file "les.pfx" was canceled.

证书与 .csproj 位于同一文件夹中,并且正在导入到商店中。

Here's the cert info and the Thumbprint matches what's in the .csproj file:

有什么我可能在这里遗漏的想法吗?

【问题讨论】:

    标签: visual-studio clickonce sign signtool


    【解决方案1】:

    根据错误信息,您必须将证书导入代理机器的个人存储中。当您从个人商店引用证书时,它不会询问密码,因此您可以访问您的代码签名证书。

    如果使用 ClickOnce 构建多个项目,则必须将证书导入每个项目。

    请尝试使用 Visual Studio 命令提示符在您的构建代理机器中导入证书:

    1. 单击开始所有程序Microsoft Visual StudioVisual Studio 工具Visual Studio 命令提示符
    2. 键入以下命令示例:

      sn -i "c:\Pathtofile\.pfx" VS_KEY_C1D3ACB8FBF1AGK4
      

    注意:带有 -i 参数的 sn.exe 将密钥对从名为的密钥容器中安装。

    1. 将 pfx 文件重新导入 Visual Studio。

    您也可以尝试创建一个 PowerShell 脚本并在您的构建定义中运行 pre-build scripts 以导入证书。

    供您参考的 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()
    

    参考这些线程:

    【讨论】:

      猜你喜欢
      • 2014-03-29
      • 2021-04-30
      • 1970-01-01
      • 2018-11-17
      • 2014-01-18
      • 2014-01-25
      • 2015-07-06
      • 1970-01-01
      • 2022-07-03
      相关资源
      最近更新 更多