如何在Visual Studio中获取正确的FrameworkSDKPath

问题描述 投票:1回答:2

我试图让我的WiX引导程序安装程序在Visual Studio中签名。我正在关注WiX: Digitally Sign BootStrapper project中显示的示例

不幸的是,必须使用显式路径来签名工具才能让它工作......

  <Target Name="UsesFrameworkSdk">
    <GetFrameworkSdkPath>
      <Output TaskParameter="Path" PropertyName="FrameworkSdkPath" />
    </GetFrameworkSdkPath>
    <Message Text="SDK path = '$(FrameworkSdkPath)'" Importance="high"/>
  </Target>
  <Target Name="UsesSignTool" DependsOnTargets="UsesFrameworkSdk">
    <PropertyGroup>
      <SignToolPath>C:\Program Files (x86)\Windows Kits\10\bin\x86\signtool.exe</SignToolPath>
    </PropertyGroup>
  </Target>

FrameworkSdkPath变量返回“C:\ Program Files(x86)\ Microsoft SDKs \ Windows \ v10.0A \”,这不是签名工具的位置。

如果我启动VS命令工具,则将环境变量WindowsSdkDir设置为包含signtool.exe的目录。但是,此变量未在Visual Studio中设置。

如何正确地做到这一点,所以我不必设置明确的路径?

visual-studio msbuild
2个回答
1
投票

如何正确地做到这一点,所以我不必设置明确的路径?

从示例中,我们可以从注册表中获取路径。像这样:

 <Target Name="UsesFrameworkSdk">
    <GetFrameworkSdkPath>
      <Output TaskParameter="Path" PropertyName="FrameworkSdkPath" />
    </GetFrameworkSdkPath>
    <PropertyGroup>
      <Win10SDK>$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0@InstallationFolder)</Win10SDK>
    </PropertyGroup>
    <Message Text="SDK path = '$(Win10SDK)'" Importance="high"/>
  </Target>

  <Target Name="UsesSignTool" DependsOnTargets="UsesFrameworkSdk">
    <PropertyGroup>
      <SignToolPath Condition="('@(SignToolPath)'=='') and Exists('$(Win10SDK)\bin\x86\signtool.exe')">$(Win10SDK)\bin\x86\signtool.exe</SignToolPath>
    </PropertyGroup>
  </Target>

enter image description here


0
投票

接受的答案不再适用于最新版本的SDK,因为bin文件夹已移动。这是更正:

<Target Name="UsesFrameworkSdk">
  <PropertyGroup>

<Win10SDKBinPath>$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0@InstallationFolder)bin\</Win10SDKBinPath>

<Win10SDKVersion>$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0@ProductVersion).0\</Win10SDKVersion>
      <Win10SDKVerBinPath>$(Win10SDKBinPath)$(Win10SDKVersion)
    </Win10SDKVerBinPath>
  </PropertyGroup>
</Target>
<Target Name="UsesSignTool" DependsOnTargets="UsesFrameworkSdk">
  <PropertyGroup>
    <SignToolPath Condition="('@(SignToolPath)'=='') and Exists('$(Win10SDKVerBinPath)x86\signtool.exe')">$(Win10SDKVerBinPath)x86\signtool.exe</SignToolPath>
  </PropertyGroup>
</Target>
© www.soinside.com 2019 - 2024. All rights reserved.