@@ -5,17 +5,16 @@ $ErrorActionPreference = 'Stop'
55# Unique set of Windows SDK versions referenced in files
66$versions = New-Object System.Collections.Generic.HashSet[System.String ]
77
8- function Get-Nodes
9- {
8+ function Get-Nodes {
109 param (
11- [parameter (ValueFromPipeline = $true )]
12- [xml ] $xml ,
13- [parameter (Mandatory = $true )]
10+ [parameter (ValueFromPipeline = $true )]
11+ [xml ] $xml ,
12+ [parameter (Mandatory = $true )]
1413 [string ] $nodeName )
1514
1615 # Try the old style csproj. Also format required for .targets and .props files
1716 $n = Select-Xml - Xml $xml.Project - Namespace @ {d = $ns } - XPath " //d:$nodeName "
18-
17+
1918 # Try the SDK-style files
2019 if (! $n ) {
2120 $r = Select-Xml - Xml $xml.Project - XPath " //$nodeName "
@@ -24,11 +23,10 @@ function Get-Nodes
2423 return $r
2524}
2625
27- function Get-NodeValue
28- {
26+ function Get-NodeValue {
2927 param (
30- [parameter (ValueFromPipeline = $true )]
31- [xml ] $xml ,
28+ [parameter (ValueFromPipeline = $true )]
29+ [xml ] $xml ,
3230 [string ] $nodeName )
3331
3432 $node = get-nodes $xml $nodeName
@@ -42,10 +40,9 @@ function Get-NodeValue
4240 return [string ]" "
4341}
4442
45- function Get-SdkVersion
46- {
43+ function Get-SdkVersion {
4744 param (
48- [Parameter (ValueFromPipeline = $true )] $file )
45+ [Parameter (ValueFromPipeline = $true )] $file )
4946
5047 [xml ] $xml = Get-Content $file
5148
@@ -67,26 +64,22 @@ function Get-SdkVersion
6764 $versions.Add (" 10.0." + $version + " .0" ) | Out-Null
6865}
6966
70- function Test-RegistryPathAndValue
71- {
67+ function Test-RegistryPathAndValue {
7268 param (
73- [parameter (Mandatory = $true )]
69+ [parameter (Mandatory = $true )]
7470 [ValidateNotNullOrEmpty ()]
7571 [string ] $path ,
76- [parameter (Mandatory = $true )]
72+ [parameter (Mandatory = $true )]
7773 [ValidateNotNullOrEmpty ()]
7874 [string ] $value )
7975
80- try
81- {
82- if (Test-Path $path )
83- {
76+ try {
77+ if (Test-Path $path ) {
8478 Get-ItemProperty - Path $path | Select-Object - ExpandProperty $value - ErrorAction Stop | Out-Null
8579 return $true
8680 }
8781 }
88- catch
89- {
82+ catch {
9083 }
9184
9285 return $false
@@ -101,24 +94,18 @@ function Test-InstallWindowsSdk([string] $WindowsSDKVersion) {
10194
10295 $WindowsSDKInstalledRegPath = " $WindowsSDKRegPath \$WindowsSDKVersion \Installed Options"
10396
104- if (Test-RegistryPathAndValue - Path $WindowsSDKRegPath - Value $WindowsSDKRegRootKey )
105- {
97+ if (Test-RegistryPathAndValue - Path $WindowsSDKRegPath - Value $WindowsSDKRegRootKey ) {
10698 # A Windows SDK is installed
10799 # Is an SDK of our version installed with the options we need?
108- if (Test-RegistryPathAndValue - Path $WindowsSDKInstalledRegPath - Value " $WindowsSDKOptions " )
109- {
100+ if (Test-RegistryPathAndValue - Path $WindowsSDKInstalledRegPath - Value " $WindowsSDKOptions " ) {
110101 # It appears we have what we need. Double check the disk
111102 $sdkRoot = Get-ItemProperty - Path $WindowsSDKRegPath | Select-Object - ExpandProperty $WindowsSDKRegRootKey
112- if ($sdkRoot )
113- {
114- if (Test-Path $sdkRoot )
115- {
103+ if ($sdkRoot ) {
104+ if (Test-Path $sdkRoot ) {
116105 $refPath = Join-Path $sdkRoot " References\$WindowsSDKVersion "
117- if (Test-Path $refPath )
118- {
106+ if (Test-Path $refPath ) {
119107 $umdPath = Join-Path $sdkRoot " UnionMetadata\$WindowsSDKVersion "
120- if (Test-Path $umdPath )
121- {
108+ if (Test-Path $umdPath ) {
122109 # Pretty sure we have what we need
123110 $retval = $false
124111 }
@@ -131,13 +118,13 @@ function Test-InstallWindowsSdk([string] $WindowsSDKVersion) {
131118 return $retval
132119}
133120
134- if (! $PSScriptRoot ){
121+ if (! $PSScriptRoot ) {
135122 $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path - Parent
136123}
137124
138125Write-Host - NoNewline " Locating referenced Windows SDK versions..."
139126
140- Get-ChildItem * .csproj - Recurse | ForEach-Object { get-sdkversion $_ }
127+ Get-ChildItem * .csproj - Recurse | ForEach-Object { get-sdkversion $_ }
141128Get-ChildItem * .targets - Recurse | ForEach-Object { get-sdkversion $_ }
142129Get-ChildItem * .props - Recurse | ForEach-Object { get-sdkversion $_ }
143130
@@ -146,20 +133,21 @@ Write-Host
146133
147134$anyInstallRequired = $false ;
148135
149- foreach ($version in $versions ) {
136+ foreach ($version in $versions ) {
150137 if ($version -match " 10\.0\.\d{5}\.0" ) {
151138 $installRequired = Test-InstallWindowsSDK $version
152139 Write-Host " Windows SDK '$version ' install required: $installRequired "
153- if ($installRequired ) {
140+ if ($installRequired ) {
154141 # Automatically invoke Install-WindowsSDKIso.ps1 ?
155142 $anyInstallRequired = $true
156143 }
157144 }
158145}
159146
160147Write-Host
161- if ($anyInstallRequired ) {
148+ if ($anyInstallRequired ) {
162149 throw " At least one Windows SDK is missing from this machine"
163- } else {
150+ }
151+ else {
164152 Write-Host " All referenced Windows SDKs are installed!"
165153}
0 commit comments