PostBuild Event fails in Visual Studio after SignTool.exe error

后端 未结 1 1052
萌比男神i
萌比男神i 2020-12-29 08:41

We have a project in Visual Studio 2010 that runs a batch file in the post-build event. That batch calls to signtool.exe from Microsoft SDK to sign and timestamp the binary

1条回答
  •  梦谈多话
    2020-12-29 09:23

    After spending much time experimenting and searching, found an article, mentioned here in a comment. It looks like Visual Studio scans the output, searching for some special keywords. Signtool.exe outputs among the other EXEC : SignTool error : An error occurred, which seems like enough to alert Visual Studio that there was an error.

    So, the solution proposed was to redirect output and error streams to nul as 2>nul 1>nul. Errorlevel will still be set, so you will be able to figure out if error occured. But you may have to print some extra messages to see the status:

    REM try to timestamp the file...
    signtool.exe timestamp /t %timestamp_server% %1 2>nul 1>nul
    
    if errorlevel 0 if not errorlevel 1 (
        echo Successfully timestamped: %1
        GOTO succeeded
    )
    echo Timestamping failed for %1
    

    Now Visual Studio is happy:

    1>------ Build started: Project: myproject, Configuration: NonOptimized x64 ------
    1>  Done Adding Additional Store
    1>  Successfully signed: E:\tfs\MySolution\bin\x64\NonOptimized\myproject.dll
    1>  
    1>  Timestamping failed for "E:\tfs\MySolution\bin\x64\NonOptimized\myproject.dll"
    1>  Successfully timestamped: "E:\tfs\MySolution\bin\x64\NonOptimized\myproject.dll"
    1>  signfile.bat exit code is 0.
    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
    

    In fact, just adding 2>nul would be enough to fix it. Error stream will still be printed: Number of errors: 1, but it does not cause a problem.

    0 讨论(0)
提交回复
热议问题