@@ -34,10 +34,7 @@ public struct ToolchainVersion
34
34
35
35
public bool IsValid => Version > 0 && ! string . IsNullOrEmpty ( Directory ) ;
36
36
37
- public override string ToString ( )
38
- {
39
- return string . Format ( "{0} (version: {1})" , Directory , Version ) ;
40
- }
37
+ public override string ToString ( ) => $ "{ Directory } (version: { Version } )";
41
38
}
42
39
43
40
/// <summary>
@@ -53,13 +50,6 @@ public struct Version
53
50
54
51
public static class MSVCToolchain
55
52
{
56
- static void DumpSdks ( string sku , IEnumerable < ToolchainVersion > sdks )
57
- {
58
- Console . WriteLine ( "\n {0} SDKs:" , sku ) ;
59
- foreach ( var sdk in sdks )
60
- Console . WriteLine ( "\t ({0}) {1}" , sdk . Version , sdk . Directory ) ;
61
- }
62
-
63
53
/// <summary>Dumps the detected SDK versions.</summary>
64
54
public static void DumpSdks ( )
65
55
{
@@ -120,24 +110,6 @@ public static Version GetCLVersion(VisualStudioVersion vsVersion)
120
110
return clVersion ;
121
111
}
122
112
123
- static int GetVisualStudioVersion ( VisualStudioVersion version )
124
- {
125
- switch ( version )
126
- {
127
- case VisualStudioVersion . VS2012 :
128
- return 11 ;
129
- case VisualStudioVersion . VS2013 :
130
- return 12 ;
131
- case VisualStudioVersion . VS2015 :
132
- return 14 ;
133
- case VisualStudioVersion . VS2017 :
134
- case VisualStudioVersion . Latest :
135
- return 15 ;
136
- default :
137
- throw new Exception ( "Unknown Visual Studio version" ) ;
138
- }
139
- }
140
-
141
113
public static ToolchainVersion GetVSToolchain ( VisualStudioVersion vsVersion )
142
114
{
143
115
List < ToolchainVersion > vsSdks ;
@@ -173,7 +145,7 @@ public static ToolchainVersion GetWindowsKitsToolchain(VisualStudioVersion vsVer
173
145
if ( match . Success )
174
146
windowsSdkMajorVer = int . Parse ( match . Groups [ 1 ] . Value ) ;
175
147
176
- match = Regex . Match ( vcVarsFile , @ "KitsRoot([1-9][0-9]*)") ;
148
+ match = Regex . Match ( vcVarsFile , "KitsRoot([1-9][0-9]*)" ) ;
177
149
if ( match . Success )
178
150
kitsRootKey = match . Groups [ 0 ] . Value ;
179
151
@@ -186,7 +158,7 @@ public static ToolchainVersion GetWindowsKitsToolchain(VisualStudioVersion vsVer
186
158
// If for some reason we cannot find the SDK version reported by VS
187
159
// in the system, then fallback to the latest version found.
188
160
if ( windowsKitSdk . Value == null )
189
- windowsKitSdk = windowsKitsSdks . Last ( ) ;
161
+ windowsKitSdk = windowsKitsSdks . Last ( ) ;
190
162
return windowsKitSdk ;
191
163
}
192
164
@@ -225,6 +197,31 @@ public static List<string> GetSystemIncludes(VisualStudioVersion wantedVsVersion
225
197
return new List < string > ( ) ;
226
198
}
227
199
200
+ private static void DumpSdks ( string sku , IEnumerable < ToolchainVersion > sdks )
201
+ {
202
+ Console . WriteLine ( "\n {0} SDKs:" , sku ) ;
203
+ foreach ( var sdk in sdks )
204
+ Console . WriteLine ( "\t ({0}) {1}" , sdk . Version , sdk . Directory ) ;
205
+ }
206
+
207
+ private static int GetVisualStudioVersion ( VisualStudioVersion version )
208
+ {
209
+ switch ( version )
210
+ {
211
+ case VisualStudioVersion . VS2012 :
212
+ return 11 ;
213
+ case VisualStudioVersion . VS2013 :
214
+ return 12 ;
215
+ case VisualStudioVersion . VS2015 :
216
+ return 14 ;
217
+ case VisualStudioVersion . VS2017 :
218
+ case VisualStudioVersion . Latest :
219
+ return 15 ;
220
+ default :
221
+ throw new Exception ( "Unknown Visual Studio version" ) ;
222
+ }
223
+ }
224
+
228
225
private static List < string > GetSystemIncludes ( VisualStudioVersion vsVersion , string vsDir )
229
226
{
230
227
if ( vsVersion == VisualStudioVersion . VS2017 )
@@ -405,7 +402,7 @@ public static bool GetWindowsSdks(out List<ToolchainVersion> versions)
405
402
GetToolchainsFromSystemRegistry (
406
403
"HKEY_LOCAL_MACHINE\\ SOFTWARE\\ Microsoft\\ Microsoft SDKs\\ Windows" ,
407
404
"InstallationFolder" , versions , RegistryView . Registry64 ) ;
408
- }
405
+ }
409
406
versions . Sort ( ( v1 , v2 ) => ( int ) ( v1 . Version - v2 . Version ) ) ;
410
407
return versions . Count != 0 ;
411
408
}
@@ -473,7 +470,13 @@ public static bool GetVisualStudioSdks(out List<ToolchainVersion> versions)
473
470
return true ;
474
471
}
475
472
473
+ /// <summary>
476
474
/// Read registry strings looking for matching values.
475
+ /// </summary>
476
+ /// <param name="keyPath">The path to the key in the registry.</param>
477
+ /// <param name="matchValue">The value to match in the located key, if any.</param>
478
+ /// <param name="entries">The collected tool-chains.</param>
479
+ /// <param name="view">The type of registry, 32 or 64, to target.</param>
477
480
public static bool GetToolchainsFromSystemRegistryValues ( string keyPath ,
478
481
string matchValue , ICollection < ToolchainVersion > entries , RegistryView view )
479
482
{
@@ -518,6 +521,7 @@ public static bool GetToolchainsFromSystemRegistryValues(string keyPath,
518
521
return true ;
519
522
}
520
523
524
+ /// <summary>
521
525
/// Read registry string.
522
526
/// This also supports a means to look for high-versioned keys by use
523
527
/// of a $VERSION placeholder in the key path.
@@ -526,7 +530,12 @@ public static bool GetToolchainsFromSystemRegistryValues(string keyPath,
526
530
/// I.e. "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio".
527
531
/// There can be additional characters in the component. Only the numeric
528
532
/// characters are compared.
529
- static bool GetToolchainsFromSystemRegistry ( string keyPath , string valueName ,
533
+ /// </summary>
534
+ /// <param name="keyPath">The path to the key in the registry.</param>
535
+ /// <param name="matchValue">The value to match in the located key, if any.</param>
536
+ /// <param name="entries">The collected tool-chains.</param>
537
+ /// <param name="view">The type of registry, 32 or 64, to target.</param>
538
+ private static bool GetToolchainsFromSystemRegistry ( string keyPath , string valueName ,
530
539
ICollection < ToolchainVersion > entries , RegistryView view )
531
540
{
532
541
string subKey ;
@@ -549,7 +558,7 @@ static bool GetToolchainsFromSystemRegistry(string keyPath, string valueName,
549
558
return true ;
550
559
}
551
560
552
- static bool HandleToolchainRegistrySubKey ( out ToolchainVersion entry ,
561
+ private static bool HandleToolchainRegistrySubKey ( out ToolchainVersion entry ,
553
562
RegistryKey key , string valueName , string subKeyName )
554
563
{
555
564
entry = new ToolchainVersion ( ) ;
@@ -585,7 +594,7 @@ static bool HandleToolchainRegistrySubKey(out ToolchainVersion entry,
585
594
return true ;
586
595
}
587
596
588
- static RegistryHive GetRegistryHive ( string keyPath , out string subKey )
597
+ private static RegistryHive GetRegistryHive ( string keyPath , out string subKey )
589
598
{
590
599
var hive = ( RegistryHive ) 0 ;
591
600
subKey = null ;
@@ -647,7 +656,7 @@ private static List<string> GetSystemIncludesVS2017(string vsDir)
647
656
where package . GetId ( ) . Contains ( "Microsoft.VisualStudio.Component.VC.Tools" )
648
657
orderby package . GetId ( )
649
658
select package ;
650
- if ( vc_tools . Count ( ) > 0 )
659
+ if ( vc_tools . Any ( ) )
651
660
{ // Tools found, get path
652
661
var path = instance . GetInstallationPath ( ) ;
653
662
var versionFilePath = path + @"\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt" ;
@@ -664,7 +673,7 @@ where sdk.GetId().Contains("Windows10SDK")
664
673
var win8sdks = from sdk in sdks
665
674
where sdk . GetId ( ) . Contains ( "Windows81SDK" )
666
675
select sdk ;
667
- if ( win10sdks . Count ( ) > 0 )
676
+ if ( win10sdks . Any ( ) )
668
677
{
669
678
var sdk = win10sdks . Last ( ) ;
670
679
var matchVersion = regexWinSDK10Version . Match ( sdk . GetId ( ) ) ;
@@ -697,7 +706,7 @@ where sdk.GetId().Contains("Windows81SDK")
697
706
includes . Add ( ucrt ) ;
698
707
}
699
708
}
700
- else if ( win8sdks . Count ( ) > 0 )
709
+ else if ( win8sdks . Any ( ) )
701
710
{
702
711
includes . Add ( @"C:\Program Files (x86)\Windows Kits\8.1\include\shared" ) ;
703
712
includes . Add ( @"C:\Program Files (x86)\Windows Kits\8.1\include\um" ) ;
0 commit comments