我参与了基于Visual Studio 2012的项目。 在那里可以通过以下方式找到signtool.exe的路径:
<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>
现在我想将项目移植到Visual Studio 2017。 安装此方法以获取路径不再有效 因为缺少Windows SDK 8。
我已经安装了Click Once组件和Windows 10 SDK。 因此signtool.exe可用。
有人可以告诉我如何使用Visual Studio 2017找到路径吗?
答案 0 :(得分:3)
有人可以告诉我如何使用Visual Studio 2017找到路径吗?
您可以根据配置从注册表中找到并设置SignToolPath
变量:
<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>
我们可以将此属性设置为项目文件或.target
文件,然后将其导入项目文件。
或者,您可以将环境变量设置为SignToolPath
,即全局系统路径(通过ControlPanel-&gt;系统 - >高级系统设置 - >环境变量):
C:\Program Files (x86)\Windows Kits\10\bin\x86
希望这有帮助。
答案 1 :(得分:0)
根据Leo的回答,这是我更新的Windows Kit 10的PropertyGroup。尚未经过全面测试,但可以在我的机器上使用;-)
<PropertyGroup>
<!-- Windows Kits 10 -->
<WindowsKitsRoot Condition="'$(WindowsKitsRoot)' == ''">$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots', 'KitsRoot10', null, RegistryView.Registry32, RegistryView.Default))</WindowsKitsRoot>
<SignToolPath Condition="'$(WindowsKitsRoot)' != '' And '$(SignToolPath)' == '' And exists('$(WindowsKitsRoot)bin\10.0.18362.0\')">$(WindowsKitsRoot)bin\10.0.18362.0\$(Platform)\</SignToolPath>
<SignToolPath Condition="'$(WindowsKitsRoot)' != '' And '$(SignToolPath)' == '' And exists('$(WindowsKitsRoot)bin\10.0.18362.0\')">$(WindowsKitsRoot)bin\10.0.17763.0\$(Platform)\</SignToolPath>
<SignToolPath Condition="'$(WindowsKitsRoot)' != '' And '$(SignToolPath)' == '' And exists('$(WindowsKitsRoot)bin\10.0.18362.0\')">$(WindowsKitsRoot)bin\10.0.17134.0\$(Platform)\</SignToolPath>
<SignToolPath Condition="'$(WindowsKitsRoot)' != '' And '$(SignToolPath)' == '' And exists('$(WindowsKitsRoot)bin\10.0.18362.0\')">$(WindowsKitsRoot)bin\10.0.16299.0\$(Platform)\</SignToolPath>
<!-- Windows Kits 8 and older -->
<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>
答案 2 :(得分:0)
我最近发现了一个注册表项,其中包含signtool.exe所需的路径。
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots]
"WdkBinRootVersioned" = "C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\"
所以这对我有用:
<PropertyGroup>
<WindowsKitsRoot>$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots', 'WdkBinRootVersioned', null, RegistryView.Registry32, RegistryView.Default))</WindowsKitsRoot>
<SignToolPath Condition="'$(SignToolPath)' == '' And '$(Platform)' == 'AnyCPU'">$(WindowsKitsRoot)x86\</SignToolPath>
<SignToolPath Condition="'$(SignToolPath)' == ''">$(WindowsKitsRoot)$(Platform)\</SignToolPath>
</PropertyGroup>
答案 3 :(得分:0)
基于Leo的响应,它独立于Windows Kits版本,但使用Target。 $(SignToolPath)将包含signtool.exe的路径。
主要思想是在MSBuild中使用标准排序顺序,并将ItemGroup SignToolPaths的最后一项设置为属性SignToolPath
<Target Name="ResolveSignToolPath" BeforeTargets="SignFile">
<ItemGroup>
<KitsRegKeys Include="KitsRoot" />
<KitsRegKeys Include="KitsRoot81" />
<KitsRegKeys Include="KitsRoot10" />
<KitsRegKeyValues Include="@(KitsRegKeys)">
<Value>$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots', '%(KitsRegKeys.Identity)', null, RegistryView.Registry32, RegistryView.Default))</Value>
</KitsRegKeyValues>
</ItemGroup>
<PropertyGroup>
<WindowsKitsRoot>%(KitsRegKeyValues.Value)</WindowsKitsRoot>
<SignToolPlatform Condition="'$(SignToolPlatform)'=='' And '$(Platform)'!='AnyCPU'">$(Platform)</SignToolPlatform>
<SignToolPlatform Condition="'$(SignToolPlatform)'==''">x86</SignToolPlatform>
</PropertyGroup>
<ItemGroup>
<SignToolPaths Include="$(WindowsKitsRoot)bin\**\$(SignToolPlatform)\signtool.exe"/>
</ItemGroup>
<PropertyGroup>
<SignToolPath>%(SignToolPaths.Identity)</SignToolPath>
</PropertyGroup>
<Error Condition="'$(SignToolPath)'=='' Or !Exists('$(SignToolPath)')"
Text="In order to sign file, this package requires access to the signtool.exe tool from the Windows Kits, which was not found. Please either: 1) Supply a correct path to your Windows Kits bin directory containing signtool.exe by setting %24(SignToolPath) OR 2) Install Windows Kits" />
<!-- <Message Text="Signing $(SignToolPath)" Importance="high" /> -->
</Target>