@@ -32,9 +32,11 @@ public sealed class DotNetMSBuildSdkResolver : SdkResolver
32
32
private readonly Func < string , string , string ? > _getMsbuildRuntime ;
33
33
private readonly NETCoreSdkResolver _netCoreSdkResolver ;
34
34
35
+ private const string DOTNET_HOST = nameof ( DOTNET_HOST ) ;
35
36
private const string DotnetHostExperimentalKey = "DOTNET_EXPERIMENTAL_HOST_PATH" ;
36
37
private const string MSBuildTaskHostRuntimeVersion = "SdkResolverMSBuildTaskHostRuntimeVersion" ;
37
-
38
+ private const string SdkResolverHonoredGlobalJson = "SdkResolverHonoredGlobalJson" ;
39
+ private const string SdkResolverGlobalJsonPath = "SdkResolverGlobalJsonPath" ;
38
40
private static CachingWorkloadResolver _staticWorkloadResolver = new ( ) ;
39
41
40
42
private bool _shouldLog = false ;
@@ -68,6 +70,7 @@ private sealed class CachedState
68
70
public string ? GlobalJsonPath ;
69
71
public IDictionary < string , string ? > ? PropertiesToAdd ;
70
72
public CachingWorkloadResolver ? WorkloadResolver ;
73
+ public IDictionary < string , string ? > ? EnvironmentVariablesToAdd ;
71
74
}
72
75
73
76
public override SdkResult ? Resolve ( SdkReference sdkReference , SdkResolverContext context , SdkResultFactory factory )
@@ -78,6 +81,7 @@ private sealed class CachedState
78
81
string ? globalJsonPath = null ;
79
82
IDictionary < string , string ? > ? propertiesToAdd = null ;
80
83
IDictionary < string , SdkResultItem > ? itemsToAdd = null ;
84
+ IDictionary < string , string ? > ? environmentVariablesToAdd = null ;
81
85
List < string > ? warnings = null ;
82
86
CachingWorkloadResolver ? workloadResolver = null ;
83
87
@@ -99,6 +103,7 @@ private sealed class CachedState
99
103
globalJsonPath = priorResult . GlobalJsonPath ;
100
104
propertiesToAdd = priorResult . PropertiesToAdd ;
101
105
workloadResolver = priorResult . WorkloadResolver ;
106
+ environmentVariablesToAdd = priorResult . EnvironmentVariablesToAdd ;
102
107
103
108
logger ? . LogMessage ( $ "\t Dotnet root: { dotnetRoot } ") ;
104
109
logger ? . LogMessage ( $ "\t MSBuild SDKs Dir: { msbuildSdksDir } ") ;
@@ -139,9 +144,9 @@ private sealed class CachedState
139
144
logger ? . LogMessage ( $ "\t Resolved SDK directory: { resolverResult . ResolvedSdkDirectory } ") ;
140
145
logger ? . LogMessage ( $ "\t global.json path: { resolverResult . GlobalJsonPath } ") ;
141
146
logger ? . LogMessage ( $ "\t Failed to resolve SDK from global.json: { resolverResult . FailedToResolveSDKSpecifiedInGlobalJson } ") ;
142
-
143
- msbuildSdksDir = Path . Combine ( resolverResult . ResolvedSdkDirectory , "Sdks" ) ;
144
- netcoreSdkVersion = new DirectoryInfo ( resolverResult . ResolvedSdkDirectory ) . Name ;
147
+ string dotnetSdkDir = resolverResult . ResolvedSdkDirectory ;
148
+ msbuildSdksDir = Path . Combine ( dotnetSdkDir , "Sdks" ) ;
149
+ netcoreSdkVersion = new DirectoryInfo ( dotnetSdkDir ) . Name ;
145
150
globalJsonPath = resolverResult . GlobalJsonPath ;
146
151
147
152
// These are overrides that are used to force the resolved SDK tasks and targets to come from a given
@@ -197,20 +202,22 @@ private sealed class CachedState
197
202
}
198
203
199
204
string ? fullPathToMuxer =
200
- TryResolveMuxerFromSdkResolution ( resolverResult )
205
+ TryResolveMuxerFromSdkResolution ( dotnetSdkDir )
201
206
?? Path . Combine ( dotnetRoot , RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? Constants . DotNetExe : Constants . DotNet ) ;
202
207
if ( File . Exists ( fullPathToMuxer ) )
203
208
{
204
- propertiesToAdd ??= new Dictionary < string , string ? > ( ) ;
205
- propertiesToAdd . Add ( DotnetHostExperimentalKey , fullPathToMuxer ) ;
209
+ environmentVariablesToAdd ??= new Dictionary < string , string ? > ( 1 )
210
+ {
211
+ [ DOTNET_HOST ] = fullPathToMuxer
212
+ } ;
206
213
}
207
214
else
208
215
{
209
- logger ? . LogMessage ( $ "Could not set '{ DotnetHostExperimentalKey } ' because dotnet executable '{ fullPathToMuxer } ' does not exist.") ;
216
+ logger ? . LogMessage ( $ "Could not set '{ DOTNET_HOST } ' environment variable because dotnet executable '{ fullPathToMuxer } ' does not exist.") ;
210
217
}
211
218
212
219
string ? runtimeVersion = dotnetRoot != null ?
213
- _getMsbuildRuntime ( resolverResult . ResolvedSdkDirectory , dotnetRoot ) :
220
+ _getMsbuildRuntime ( dotnetSdkDir , dotnetRoot ) :
214
221
null ;
215
222
if ( ! string . IsNullOrEmpty ( runtimeVersion ) )
216
223
{
@@ -224,7 +231,7 @@ private sealed class CachedState
224
231
225
232
if ( resolverResult . FailedToResolveSDKSpecifiedInGlobalJson )
226
233
{
227
- logger ? . LogMessage ( $ "Could not resolve SDK specified in '{ resolverResult . GlobalJsonPath } '. Ignoring global.json for this resolution.") ;
234
+ logger ? . LogMessage ( $ "Could not resolve SDK specified in '{ globalJsonPath } '. Ignoring global.json for this resolution.") ;
228
235
229
236
if ( warnings == null )
230
237
{
@@ -241,8 +248,9 @@ private sealed class CachedState
241
248
}
242
249
243
250
propertiesToAdd ??= new Dictionary < string , string ? > ( ) ;
244
- propertiesToAdd . Add ( "SdkResolverHonoredGlobalJson" , "false" ) ;
245
- propertiesToAdd . Add ( "SdkResolverGlobalJsonPath" , resolverResult . GlobalJsonPath ) ;
251
+ propertiesToAdd . Add ( SdkResolverHonoredGlobalJson , "false" ) ;
252
+ // TODO: this would ideally be reported anytime it was non-null - that may cause more imports though?
253
+ propertiesToAdd . Add ( SdkResolverGlobalJsonPath , globalJsonPath ) ;
246
254
247
255
if ( logger != null )
248
256
{
@@ -258,7 +266,8 @@ private sealed class CachedState
258
266
NETCoreSdkVersion = netcoreSdkVersion ,
259
267
GlobalJsonPath = globalJsonPath ,
260
268
PropertiesToAdd = propertiesToAdd ,
261
- WorkloadResolver = workloadResolver
269
+ WorkloadResolver = workloadResolver ,
270
+ EnvironmentVariablesToAdd = environmentVariablesToAdd
262
271
} ;
263
272
264
273
// First check if requested SDK resolves to a workload SDK pack
@@ -285,7 +294,7 @@ private sealed class CachedState
285
294
msbuildSdkDir ) ;
286
295
}
287
296
288
- return factory . IndicateSuccess ( msbuildSdkDir , netcoreSdkVersion , propertiesToAdd , itemsToAdd , warnings ) ;
297
+ return factory . IndicateSuccess ( msbuildSdkDir , netcoreSdkVersion , propertiesToAdd , itemsToAdd , warnings , environmentVariablesToAdd : environmentVariablesToAdd ) ;
289
298
}
290
299
291
300
/// <summary>
@@ -295,10 +304,10 @@ private sealed class CachedState
295
304
/// SDK layouts always have a defined relationship to the location of the muxer -
296
305
/// the muxer binary should be exactly two directories above the SDK directory.
297
306
/// </remarks>
298
- private static string ? TryResolveMuxerFromSdkResolution ( SdkResolutionResult resolverResult )
307
+ private static string ? TryResolveMuxerFromSdkResolution ( string resolvedSdkDirectory )
299
308
{
300
309
var expectedFileName = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? Constants . DotNetExe : Constants . DotNet ;
301
- var currentDir = resolverResult . ResolvedSdkDirectory ;
310
+ var currentDir = resolvedSdkDirectory ;
302
311
var expectedDotnetRoot = Path . GetDirectoryName ( Path . GetDirectoryName ( currentDir ) ) ;
303
312
var expectedMuxerPath = Path . Combine ( expectedDotnetRoot , expectedFileName ) ;
304
313
if ( File . Exists ( expectedMuxerPath ) )
0 commit comments