2017-09-13 183 views
0

好吧 - 这真的很奇怪。我有一个TFS构建签名文件,我收到上面的消息。如果我从构建中查看日志,它说它已成功签名并为我的文件添加了时间戳(有一个手动调用signtool的.proj文件),但是在其他步骤之下(不确定在哪里) - 我假设它在ClickOnce签署我得到错误。获取签名时发生错误:无法签署file.exe。 SignTool错误:未找到符合所有给定条件的证书

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

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

而得到这个错误:

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: 

enter image description here

enter image description here

enter image description here

任何想法我可能会错过吗?

回答

0

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

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

请尽量使用Visual Studio命令提示符导入证书在构建代理机:

  1. 点击开始>所有程序>微软的Visual Studio> Visual Studio的 工具> Visual Studio命令提示符。
  2. 键入以下命令样品:

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

    注:与-i参数的SN.EXE,从到名为密钥容器安装一个密钥对。

  3. 将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() 

参考这些线程:

相关问题