Search code examples
msbuildvisual-studio-2017signtool

How to get path to signtool.exe with Visual Studio 2017 installed


I've taken on project based on Visual Studio 2012. There the path to signtool.exe is found the following way:

<SignToolPath Condition=" Exists('$(WindowsSDK80Path)bin\x86\signtool.exe') and '$(SignToolPath)'=='' and '$(PROCESSOR_ARCHITECTURE)'=='x86' ">$(WindowsSDK80Path)bin\x86\signtool.exe</SignToolPath>
<SignToolPath Condition=" Exists('$(WindowsSDK80Path)bin\x64\signtool.exe') and '$(SignToolPath)'=='' and '$(PROCESSOR_ARCHITECTURE)'=='AMD64' ">$(WindowsSDK80Path)bin\x64\signtool.exe</SignToolPath>

Now i want to port the project to Visual Studio 2017. With this installed this way to get the path is no longer working because of missing Windows SDK 8.

I've installed the Click Once component and the Windows 10 SDK. Therefore signtool.exe is available.

Can someone tell me how to find the path with Visual Studio 2017?


Solution

  • Can someone tell me how to find the path with Visual Studio 2017?

    You could find and set the SignToolPath variable from the the registry based on the configuration:

    <PropertyGroup>
      <WindowsKitsRoot>$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots', 'KitsRoot10', null, RegistryView.Registry32, RegistryView.Default))</WindowsKitsRoot>
      <WindowsKitsRoot Condition="'$(WindowsKitsRoot)' == ''">$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots', 'KitsRoot81', null, RegistryView.Registry32, RegistryView.Default))</WindowsKitsRoot>
      <WindowsKitsRoot Condition="'$(WindowsKitsRoot)' == ''">$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots', 'KitsRoot', null, RegistryView.Registry32, RegistryView.Default))</WindowsKitsRoot>
      <SignToolPath Condition=" '$(SignToolPath)' == '' And '$(Platform)' == 'AnyCPU' ">$(WindowsKitsRoot)bin\x86\</SignToolPath>
      <SignToolPath Condition="'$(SignToolPath)' == ''">$(WindowsKitsRoot)bin\$(Platform)\</SignToolPath>
    </PropertyGroup>
    

    We could set this property into our project file or .target file then import it to the project file.

    Alternatively, you could set environment variable to SignToolPath, the global system path (via ControlPanel->System->Advanced system settings->Environment variables):

    C:\Program Files (x86)\Windows Kits\10\bin\x86
    

    Hope this helps.