@@ -5,17 +5,16 @@ $ErrorActionPreference = 'Stop'
5
5
# Unique set of Windows SDK versions referenced in files
6
6
$versions = New-Object System.Collections.Generic.HashSet[System.String ]
7
7
8
- function Get-Nodes
9
- {
8
+ function Get-Nodes {
10
9
param (
11
- [parameter (ValueFromPipeline = $true )]
12
- [xml ] $xml ,
13
- [parameter (Mandatory = $true )]
10
+ [parameter (ValueFromPipeline = $true )]
11
+ [xml ] $xml ,
12
+ [parameter (Mandatory = $true )]
14
13
[string ] $nodeName )
15
14
16
15
# Try the old style csproj. Also format required for .targets and .props files
17
16
$n = Select-Xml - Xml $xml.Project - Namespace @ {d = $ns } - XPath " //d:$nodeName "
18
-
17
+
19
18
# Try the SDK-style files
20
19
if (! $n ) {
21
20
$r = Select-Xml - Xml $xml.Project - XPath " //$nodeName "
@@ -24,11 +23,10 @@ function Get-Nodes
24
23
return $r
25
24
}
26
25
27
- function Get-NodeValue
28
- {
26
+ function Get-NodeValue {
29
27
param (
30
- [parameter (ValueFromPipeline = $true )]
31
- [xml ] $xml ,
28
+ [parameter (ValueFromPipeline = $true )]
29
+ [xml ] $xml ,
32
30
[string ] $nodeName )
33
31
34
32
$node = get-nodes $xml $nodeName
@@ -42,10 +40,9 @@ function Get-NodeValue
42
40
return [string ]" "
43
41
}
44
42
45
- function Get-SdkVersion
46
- {
43
+ function Get-SdkVersion {
47
44
param (
48
- [Parameter (ValueFromPipeline = $true )] $file )
45
+ [Parameter (ValueFromPipeline = $true )] $file )
49
46
50
47
[xml ] $xml = Get-Content $file
51
48
@@ -67,26 +64,22 @@ function Get-SdkVersion
67
64
$versions.Add (" 10.0." + $version + " .0" ) | Out-Null
68
65
}
69
66
70
- function Test-RegistryPathAndValue
71
- {
67
+ function Test-RegistryPathAndValue {
72
68
param (
73
- [parameter (Mandatory = $true )]
69
+ [parameter (Mandatory = $true )]
74
70
[ValidateNotNullOrEmpty ()]
75
71
[string ] $path ,
76
- [parameter (Mandatory = $true )]
72
+ [parameter (Mandatory = $true )]
77
73
[ValidateNotNullOrEmpty ()]
78
74
[string ] $value )
79
75
80
- try
81
- {
82
- if (Test-Path $path )
83
- {
76
+ try {
77
+ if (Test-Path $path ) {
84
78
Get-ItemProperty - Path $path | Select-Object - ExpandProperty $value - ErrorAction Stop | Out-Null
85
79
return $true
86
80
}
87
81
}
88
- catch
89
- {
82
+ catch {
90
83
}
91
84
92
85
return $false
@@ -101,24 +94,18 @@ function Test-InstallWindowsSdk([string] $WindowsSDKVersion) {
101
94
102
95
$WindowsSDKInstalledRegPath = " $WindowsSDKRegPath \$WindowsSDKVersion \Installed Options"
103
96
104
- if (Test-RegistryPathAndValue - Path $WindowsSDKRegPath - Value $WindowsSDKRegRootKey )
105
- {
97
+ if (Test-RegistryPathAndValue - Path $WindowsSDKRegPath - Value $WindowsSDKRegRootKey ) {
106
98
# A Windows SDK is installed
107
99
# 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 " ) {
110
101
# It appears we have what we need. Double check the disk
111
102
$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 ) {
116
105
$refPath = Join-Path $sdkRoot " References\$WindowsSDKVersion "
117
- if (Test-Path $refPath )
118
- {
106
+ if (Test-Path $refPath ) {
119
107
$umdPath = Join-Path $sdkRoot " UnionMetadata\$WindowsSDKVersion "
120
- if (Test-Path $umdPath )
121
- {
108
+ if (Test-Path $umdPath ) {
122
109
# Pretty sure we have what we need
123
110
$retval = $false
124
111
}
@@ -131,13 +118,13 @@ function Test-InstallWindowsSdk([string] $WindowsSDKVersion) {
131
118
return $retval
132
119
}
133
120
134
- if (! $PSScriptRoot ){
121
+ if (! $PSScriptRoot ) {
135
122
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path - Parent
136
123
}
137
124
138
125
Write-Host - NoNewline " Locating referenced Windows SDK versions..."
139
126
140
- Get-ChildItem * .csproj - Recurse | ForEach-Object { get-sdkversion $_ }
127
+ Get-ChildItem * .csproj - Recurse | ForEach-Object { get-sdkversion $_ }
141
128
Get-ChildItem * .targets - Recurse | ForEach-Object { get-sdkversion $_ }
142
129
Get-ChildItem * .props - Recurse | ForEach-Object { get-sdkversion $_ }
143
130
@@ -146,20 +133,21 @@ Write-Host
146
133
147
134
$anyInstallRequired = $false ;
148
135
149
- foreach ($version in $versions ) {
136
+ foreach ($version in $versions ) {
150
137
if ($version -match " 10\.0\.\d{5}\.0" ) {
151
138
$installRequired = Test-InstallWindowsSDK $version
152
139
Write-Host " Windows SDK '$version ' install required: $installRequired "
153
- if ($installRequired ) {
140
+ if ($installRequired ) {
154
141
# Automatically invoke Install-WindowsSDKIso.ps1 ?
155
142
$anyInstallRequired = $true
156
143
}
157
144
}
158
145
}
159
146
160
147
Write-Host
161
- if ($anyInstallRequired ) {
148
+ if ($anyInstallRequired ) {
162
149
throw " At least one Windows SDK is missing from this machine"
163
- } else {
150
+ }
151
+ else {
164
152
Write-Host " All referenced Windows SDKs are installed!"
165
153
}
0 commit comments