4
4
5
5
using System ;
6
6
using System . Collections . Generic ;
7
- using System . Diagnostics ;
8
7
using System . IO ;
9
8
using System . Resources ;
10
9
using System . Text ;
11
10
using Microsoft . Build . Framework ;
12
11
using Microsoft . Build . Utilities ;
12
+ using Microsoft . CodeAnalysis . CommandLine ;
13
13
using Roslyn . Utilities ;
14
14
15
15
namespace Microsoft . CodeAnalysis . BuildTasks
16
16
{
17
17
public abstract class ManagedToolTask : ToolTask
18
18
{
19
+ internal readonly PropertyDictionary _store = new PropertyDictionary ( ) ;
20
+
19
21
/// <summary>
20
22
/// A copy of this task, compiled for .NET Framework, is deployed into the .NET SDK. It is a bridge task
21
23
/// that is loaded into .NET Framework MSBuild but launches the .NET Core compiler. This task necessarily
@@ -77,13 +79,7 @@ internal string GenerateToolArguments()
77
79
/// </summary>
78
80
protected sealed override string GenerateCommandLineCommands ( )
79
81
{
80
- var commandLineArguments = GenerateToolArguments ( ) ;
81
- if ( UsingBuiltinTool && IsBuiltinToolRunningOnCoreClr )
82
- {
83
- commandLineArguments = RuntimeHostInfo . GetDotNetExecCommandLine ( PathToBuiltInTool , commandLineArguments ) ;
84
- }
85
-
86
- return commandLineArguments ;
82
+ return GenerateToolArguments ( ) ;
87
83
}
88
84
89
85
/// <summary>
@@ -118,12 +114,9 @@ protected sealed override string GenerateResponseFileCommands()
118
114
/// This could be the managed assembly itself (on desktop .NET on Windows),
119
115
/// or a runtime such as dotnet.
120
116
/// </summary>
121
- protected sealed override string GenerateFullPathToTool ( ) => ( UsingBuiltinTool , IsBuiltinToolRunningOnCoreClr ) switch
122
- {
123
- ( true , true ) => RuntimeHostInfo . GetDotNetPathOrDefault ( ) ,
124
- ( true , false ) => PathToBuiltInTool ,
125
- ( false , _ ) => Path . Combine ( ToolPath ?? "" , ToolExe )
126
- } ;
117
+ protected sealed override string GenerateFullPathToTool ( ) => UsingBuiltinTool
118
+ ? PathToBuiltInTool
119
+ : Path . Combine ( ToolPath ?? "" , ToolExe ) ;
127
120
128
121
protected abstract string ToolNameWithoutExtension { get ; }
129
122
@@ -139,10 +132,7 @@ protected sealed override string GenerateResponseFileCommands()
139
132
/// It returns the name of the managed assembly, which might not be the path returned by
140
133
/// GenerateFullPathToTool, which can return the path to e.g. the dotnet executable.
141
134
/// </remarks>
142
- protected sealed override string ToolName =>
143
- IsBuiltinToolRunningOnCoreClr
144
- ? $ "{ ToolNameWithoutExtension } .dll"
145
- : $ "{ ToolNameWithoutExtension } .exe";
135
+ protected sealed override string ToolName => $ "{ ToolNameWithoutExtension } { PlatformInformation . ExeExtension } ";
146
136
147
137
/// <summary>
148
138
/// This generates the command line arguments passed to the tool.
@@ -206,5 +196,17 @@ internal static string GetBuildTaskDirectory()
206
196
207
197
return buildTaskDirectory ;
208
198
}
199
+
200
+ protected override bool ValidateParameters ( )
201
+ {
202
+ // Set DOTNET_ROOT so that the apphost executables launch properly.
203
+ if ( RuntimeHostInfo . GetToolDotNetRoot ( ) is { } dotNetRoot )
204
+ {
205
+ Log . LogMessage ( "Setting {0} to '{1}'" , RuntimeHostInfo . DotNetRootEnvironmentName , dotNetRoot ) ;
206
+ EnvironmentVariables = [ .. EnvironmentVariables ?? [ ] , $ "{ RuntimeHostInfo . DotNetRootEnvironmentName } ={ dotNetRoot } "] ;
207
+ }
208
+
209
+ return base . ValidateParameters ( ) ;
210
+ }
209
211
}
210
212
}
0 commit comments