2017-09-13 182 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() 

參考這些線程:

相關問題