0

I have an AfterBuild task which signs the dll using signtool.exe via the NuGet package MSBuild.ExtensionPack

<MSBuild.ExtensionPack.Framework.CommandLine Command="&quot;C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin\signtool.exe&quot; sign &quot;/n&quot; &quot;MY CERTIFICATE&quot; &quot;/t&quot; &quot;http://timestamp.comodoca.com/authenticode&quot; &quot;$(TargetPath).&quot;" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />

Due to some differences between build environments (some remote build agents have different versions of Visual Studio and therefore the Windows SDK) this task fails when an agent has SDK version 8.0 installed.

Is it possible to trigger a different task if and only if a task fails?

i.e. if the above task fails, run an alternative task which has a different path to signtool.exe

Shevek
  • 3,869
  • 5
  • 43
  • 63

2 Answers2

1

As an alternative solution, I have come up with the following to check possible paths and use the latest version found:

<PropertyGroup>
    <SignToolPath Condition="'$(Configuration)' == 'Release' And '$(SignToolPath)' == '' And Exists('C:\Program Files (x86)\Windows Kits\8.1\bin\x64\signtool.exe')">C:\Program Files (x86)\Windows Kits\8.1\bin\x64\signtool.exe</SignToolPath>
    <SignToolPath Condition="'$(Configuration)' == 'Release' And '$(SignToolPath)' == '' And Exists('C:\Program Files (x86)\Windows Kits\8.1\bin\x86\signtool.exe')">C:\Program Files (x86)\Windows Kits\8.1\bin\x86\signtool.exe</SignToolPath>
    <SignToolPath Condition="'$(Configuration)' == 'Release' And '$(SignToolPath)' == '' And Exists('C:\Program Files (x86)\Windows Kits\8.0\bin\x64\signtool.exe')">C:\Program Files (x86)\Windows Kits\8.0\bin\x64\signtool.exe</SignToolPath>
    <SignToolPath Condition="'$(Configuration)' == 'Release' And '$(SignToolPath)' == '' And Exists('C:\Program Files (x86)\Windows Kits\8.0\bin\x86\signtool.exe')">C:\Program Files (x86)\Windows Kits\8.0\bin\x86\signtool.exe</SignToolPath>
    <SignToolPath Condition="'$(Configuration)' == 'Release' And '$(SignToolPath)' == '' And Exists('C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin\signtool.exe')">C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin\signtool.exe</SignToolPath>
    <SignToolPath Condition="'$(Configuration)' == 'Release' And '$(SignToolPath)' == '' And Exists('C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\signtool.exe')">C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\signtool.exe</SignToolPath>
    <SignToolPath Condition="'$(Configuration)' == 'Release' And '$(SignToolPath)' == '' And Exists('C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\signtool.exe')">C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\signtool.exe</SignToolPath>
    <SignToolPath Condition="'$(Configuration)' == 'Release' And '$(SignToolPath)' == '' And Exists('C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\signtool.exe')">C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\signtool.exe</SignToolPath>
</PropertyGroup>
<Error Condition="'$(Configuration)' == 'Release' And '$(SignToolPath)' == ''" Text="Unable to determine signtool path" />
<MSBuild.ExtensionPack.Framework.CommandLine Command="&quot;$(SignToolPath)&quot; sign &quot;/n&quot; &quot;MY CERTIFICATE&quot; &quot;/t&quot; &quot;http://timestamp.comodoca.com/authenticode&quot; &quot;$(TargetPath).&quot;" Condition=" '$(Configuration)' == 'Release' " />
Shevek
  • 3,869
  • 5
  • 43
  • 63
0

You can mark your task with ContinueOnError="true" and then use MSBuildLastTaskResult reserved property to check whether you task succeeded.

Something like that:

<MSBuild.ExtensionPack.Framework.CommandLine
    ContinueOnError="true"
    Command="path_to_signtool.exe"
    .... />
<MSBuild.ExtensionPack.Framework.CommandLine
    Condition="'$(MSBuildLastTaskResult)' == 'False'"
    Command="another_path_to_signtool.exe"
    .... />

See also this answer

Community
  • 1
  • 1
Igor Labutin
  • 1,406
  • 10
  • 10