27

What would be the way to retrieve the Windows SDK folder in an MSBuild task?

Using the generateBootstrapper task I'm creating a bootstrapper for my setup to be able to install the pre-requisites. This task needs the path to the folder where the pre-requisite packages are located, i.e. the Windows SDK folder

"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\"

when using Visual Studio 2008. So far I have been using a hard-coded path but this won't work on any system. Is there a better way to get the path?

This is my build script:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" 
         ToolsVersion="3.5">
    <ItemGroup>
        <BootstrapperFile Include="Microsoft.Net.Framework.2.0">
            <ProductName>.NET Framework 2.0</ProductName>
        </BootstrapperFile>
        <BootstrapperFile Include="Microsoft.Windows.Installer.3.1">
            <ProductName>Windows Installer 3.1</ProductName>
        </BootstrapperFile>
    </ItemGroup>

    <Target Name="Bootstrapper">
        <GenerateBootstrapper ApplicationFile="mySetup.msi" 
            Culture="de-DE" 
            ApplicationName="My Application" 
            OutputPath="$(OutDir)\de-DE" 
            BootstrapperItems="@(BootstrapperFile)" 
            Path="C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\" />

        <GenerateBootstrapper ApplicationFile="mySetup.msi" 
            Culture="en-US" 
            ApplicationName="My Application" 
            OutputPath="$(OutDir)\en-US" 
            BootstrapperItems="@(BootstrapperFile)" 
            Path="C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\" />
    </Target>
</Project>
1

5 Answers 5

23

You can also use the GetFrameworkSdkPath MSBuild task.

<GetFrameworkSdkPath>
  <Output TaskParameter="Path" PropertyName="WindowsSdkPath" />
</GetFrameworkSdkPath>  

For example:

<GenerateBootstrapper 
  ApplicationFile="$(SolutionName).application"
  ApplicationName="$(ClickOnceAppTitle)"
  ApplicationUrl="$(ClickOnceUrl)"
  BootstrapperItems="@(BootstrapperFile)"
  Culture="en"
  FallbackCulture="en-US"
  Path="$(WindowsSDKPath)"
  OutputPath="." /> 
8

thanks John. According to your post I edited the MSBuild script to read the folder from the registry. It was however not necessary to append "Packages" on the end, that was another mistake in my original script.

The following is the working script:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <PropertyGroup>
        <WindowsSDKPath>$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\GenericBootstrapper\3.5@Path)</WindowsSDKPath>
    </PropertyGroup>

    <ItemGroup>
        <BootstrapperFile Include="Microsoft.Net.Framework.2.0">
                <ProductName>.NET Framework 2.0</ProductName>
        </BootstrapperFile>
        <BootstrapperFile Include="Microsoft.Windows.Installer.3.1">
                <ProductName>Windows Installer 3.1</ProductName>
        </BootstrapperFile>
    </ItemGroup>

    <Target Name="Bootstrapper">
        <GenerateBootstrapper ApplicationFile="mySetup.msi" 
            Culture="de-DE" 
            ApplicationName="My Application" 
            OutputPath="$(OutDir)\de-DE" 
            BootstrapperItems="@(BootstrapperFile)" 
            Path="$(WindowsSDKPath)" />

        <GenerateBootstrapper ApplicationFile="mySetup.msi" 
            Culture="en-US" 
            ApplicationName="My Application" 
            OutputPath="$(OutDir)\en-US" 
            BootstrapperItems="@(BootstrapperFile)" 
            Path="$(WindowsSDKPath)" />
    </Target>
</Project>
1
  • 4
    Strange, I don't see that registry key or the related path after installing the Windows SDK. I'm I missing something or is everybody installing Visual Studio on their build machine?
    – jpierson
    Commented Jan 25, 2011 at 15:48
6

The install path of the Windows SDK is stored in the CurrentInstallFolder value of the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows CurrentInstallFolder

1
  • 1
    I have no idea where does the GenericBootstrapper comes from as it seems impossible to find inside the registry even if I installed SDK 6.0, 6.1, 8.0 and 8.1 on the same Windows 2012 Server machine. – s
    – sorin
    Commented Jun 19, 2015 at 13:52
5

I followed the answer from Jeremy D, but that gave the error message: error MSB3147: Could not find required file 'setup.bin' in 'C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\Engine'.

The reason is that the path to the bootstrapper (at least with V8.0A of the SDK) is a subdirectory under the path returned by the GetFrameworkSdKPath.

So the MSBuild code that works for me is:

<Target Name="AfterBuild">
  <GetFrameworkSdkPath>
    <Output TaskParameter="Path" PropertyName="WindowsSdkPath"/>
  </GetFrameworkSdkPath>
  <GenerateBootstrapper 
      ApplicationFile="myapp.msi" 
      ApplicationName="MyApplication" 
      BootstrapperItems="@(BootstrapperFile)" 
      OutputPath="$(OutputPath)" 
      Path="$(WindowsSdkPath)\Bootstrapper" />
</Target>

Note the \Bootstrapper suffix to $(WindowsSdkPath)

4

The path to the bootstrapper is stored under the registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\GenericBootstrapper\3.5

To find out the packages folder, open this, read the "Path" registry value, and append "Packages" on the end and that should give you the full path to the folder you want.

For example:

string bootStrapperPackagesFolder = "";

RegistryKey regKey = Registry.LocalMachine.OpenSubKey
   (@"SOFTWARE\Microsoft\GenericBootstrapper\3.5");
if (regKey != null)
{
   bootStrapperPackagesFolder = (string)regKey.GetValue("Path");
   if (bootStrapperPackagesFolder != null)
   {
      bootStrapperPackagesFolder += @"Packages\";
      Console.WriteLine(bootStrapperPackagesFolder);
   }
}
1
  • I have no idea where does the GenericBootstrapper comes from as it seems impossible to find inside the registry even if I installed SDK 6.0, 6.1, 8.0 and 8.1 on the same Windows 2012 Server machine.
    – sorin
    Commented Jun 19, 2015 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.