1- // Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2-
3- using Microsoft . Build . Locator ;
1+ using Microsoft . Build . Locator ;
42using Microsoft . VisualStudio . Setup . Configuration ;
53using System ;
64using System . Collections . Generic ;
@@ -20,17 +18,17 @@ internal static class MSBuildHelper
2018
2119 public static void InitializeLocator ( )
2220 {
23- if ( ! _isInitialized )
21+ if ( ! _isInitialized )
2422 {
25- if ( MSBuildLocator . CanRegister )
23+ if ( MSBuildLocator . CanRegister )
2624 {
2725 try
2826 {
2927 MSBuildLocator . RegisterDefaults ( ) ;
3028
3129 _isInitialized = true ;
3230 }
33- catch ( Exception e )
31+ catch ( Exception e )
3432 {
3533 throw new InvalidOperationException (
3634 $ "Cannot find a suitable version of MSBuild for "
@@ -47,7 +45,7 @@ public static void InitializeLocator()
4745 {
4846 var directory = FindLatestMSBuildDirectory ( context ) ;
4947
50- if ( directory == null )
48+ if ( directory == null )
5149 {
5250 return directory ;
5351 }
@@ -59,16 +57,14 @@ public static void InitializeLocator()
5957
6058 private static string ? FindLatestMSBuildDirectory ( BuildContext context )
6159 {
62- InitializeLocator ( ) ;
63-
6460 var instances = GetVisualStudioInstances ( context ) . OrderByDescending ( i => i . Version ) ;
6561
66- foreach ( var instance in instances )
62+ foreach ( var instance in instances )
6763 {
6864 // We got a Visual Studio instance but not all of them have an MSBuild instance. For instance, a Test Agent instance does not have.
6965 var directory = Path . Combine ( instance . Path , "MSBuild" , "Current" , "Bin" ) ;
7066
71- if ( Directory . Exists ( directory ) )
67+ if ( Directory . Exists ( directory ) )
7268 {
7369 return directory ;
7470 }
@@ -79,9 +75,7 @@ public static void InitializeLocator()
7975
8076 public static IEnumerable < VisualStudioInstance > GetVisualStudioInstances ( BuildContext context )
8177 {
82- InitializeLocator ( ) ;
83-
84- if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
78+ if ( ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
8579 {
8680 return [ ] ;
8781 }
@@ -101,9 +95,9 @@ public static IEnumerable<VisualStudioInstance> GetVisualStudioInstances( BuildC
10195 {
10296 enumInstances . Next ( 1 , instances , out fetched ) ;
10397
104- if ( fetched > 0 )
98+ if ( fetched > 0 )
10599 {
106- var instance = ( ISetupInstance2 ) instances [ 0 ] ;
100+ var instance = ( ISetupInstance2 ) instances [ 0 ] ;
107101
108102 list . Add (
109103 new VisualStudioInstance (
@@ -112,9 +106,9 @@ public static IEnumerable<VisualStudioInstance> GetVisualStudioInstances( BuildC
112106 instance . GetInstallationPath ( ) ) ) ;
113107 }
114108 }
115- while ( fetched > 0 ) ;
109+ while ( fetched > 0 ) ;
116110 }
117- catch ( COMException exception )
111+ catch ( COMException exception )
118112 {
119113 context . Console . WriteWarning ( $ "Cannot find VS instances: { exception . Message } " ) ;
120114
0 commit comments