1. 程式人生 > >Visual Studio 在Post build Event 呼叫 signtool

Visual Studio 在Post build Event 呼叫 signtool

最近在編譯的時候發現如果在Post build Event 呼叫 signtool 去給編譯出來的二進位制檔案進行簽名時,如果發生時間戳超時的情況就會post-build event failed with code -1

時間戳超時是經常發生的事情,因為權威的時間戳伺服器都在國外。

是不是你簽名時retry幾次,應該就沒問題了?只要保證 Errorlevel 為 0 就好了


可以使用類似的批處理:

for /L %%a in (1,1,10) do (

    REM try to timestamp the file...
    signtool.exe timestamp /t %timestamp_server% %1

    if errorlevel 0 if not errorlevel 1 GOTO succeeded

    REM wait 2 seconds...
    ping -n 2 127.0.0.1 > nul
)



but,只要你有一次超時 Visual Studio也會顯示編譯失敗


原來Visual Studio 判定Post build Event 是失敗不僅跟返回值有關,還跟控制檯輸出的錯誤的資訊有關,一旦有關鍵字 SignTool error : An error occurred

Visual Studio 判定Post build Event 是失敗的。。

感覺有點腦殘啊~~

不過知道問題了我們就有解決辦法了

可以加上 2>nul 來遮蔽出錯資訊,這樣就可以成功retry啦,哈哈哈哈