3
3
4
4
using System . Reflection ;
5
5
using Microsoft . DotNet . Cli ;
6
+ using Microsoft . DotNet . Cli . Utils ;
6
7
using Microsoft . DotNet . CommandFactory ;
8
+ using NuGet . Configuration ;
7
9
8
10
namespace Microsoft . DotNet . BuildServer
9
11
{
10
12
internal class VBCSCompilerServer : IBuildServer
11
13
{
14
+ private static readonly string s_toolsetPackageName = "microsoft.net.sdk.compilers.toolset" ;
15
+ private static readonly string s_vbcsCompilerExeFileName = "VBCSCompiler.exe" ;
16
+ private static readonly string s_shutdownArg = "-shutdown" ;
17
+
12
18
internal static readonly string VBCSCompilerPath = Path . Combine (
13
19
Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ,
14
20
"Roslyn" ,
@@ -28,18 +34,46 @@ public VBCSCompilerServer(ICommandFactory commandFactory = null)
28
34
29
35
public void Shutdown ( )
30
36
{
31
- var command = _commandFactory
32
- . Create ( "exec" , new [ ] { VBCSCompilerPath , "-shutdown" } )
33
- . CaptureStdOut ( )
34
- . CaptureStdErr ( ) ;
37
+ List < string > errors = null ;
38
+
39
+ // Shutdown the compiler from the SDK.
40
+ execute ( _commandFactory . Create ( "exec" , [ VBCSCompilerPath , s_shutdownArg ] ) , ref errors ) ;
41
+
42
+ // Shutdown toolset compilers.
43
+ var nuGetPackageRoot = SettingsUtility . GetGlobalPackagesFolder ( Settings . LoadDefaultSettings ( root : null ) ) ;
44
+ var toolsetPackageDirectory = Path . Join ( nuGetPackageRoot , s_toolsetPackageName ) ;
45
+ if ( Directory . Exists ( toolsetPackageDirectory ) )
46
+ {
47
+ foreach ( var versionDirectory in Directory . EnumerateDirectories ( toolsetPackageDirectory ) )
48
+ {
49
+ var vbcsCompilerPath = Path . Join ( versionDirectory , s_vbcsCompilerExeFileName ) ;
50
+ if ( File . Exists ( vbcsCompilerPath ) )
51
+ {
52
+ execute ( CommandFactoryUsingResolver . Create ( vbcsCompilerPath , [ s_shutdownArg ] ) , ref errors ) ;
53
+ }
54
+ }
55
+ }
35
56
36
- var result = command . Execute ( ) ;
37
- if ( result . ExitCode != 0 )
57
+ if ( errors ? . Count > 0 )
38
58
{
39
59
throw new BuildServerException (
40
60
string . Format (
41
61
LocalizableStrings . ShutdownCommandFailed ,
42
- result . StdErr ) ) ;
62
+ string . Join ( Environment . NewLine , errors ) ) ) ;
63
+ }
64
+
65
+ static void execute ( ICommand command , ref List < string > errors )
66
+ {
67
+ command = command
68
+ . CaptureStdOut ( )
69
+ . CaptureStdErr ( ) ;
70
+
71
+ var result = command . Execute ( ) ;
72
+ if ( result . ExitCode != 0 )
73
+ {
74
+ errors ??= new List < string > ( ) ;
75
+ errors . Add ( result . StdErr ) ;
76
+ }
43
77
}
44
78
}
45
79
}
0 commit comments