@@ -196,9 +196,9 @@ private sealed class CachedState
196
196
minimumVSDefinedSDKVersion ) ;
197
197
}
198
198
199
- string ? dotnetExe = dotnetRoot != null ?
200
- Path . Combine ( dotnetRoot , Constants . DotNetExe ) :
201
- null ;
199
+ string ? dotnetExe =
200
+ TryResolveDotnetExeFromSdkResolution ( resolverResult )
201
+ ?? Path . Combine ( dotnetRoot , RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? Constants . DotNetExe : Constants . DotNet ) ;
202
202
if ( File . Exists ( dotnetExe ) )
203
203
{
204
204
propertiesToAdd ??= new Dictionary < string , string ? > ( ) ;
@@ -288,6 +288,25 @@ private sealed class CachedState
288
288
return factory . IndicateSuccess ( msbuildSdkDir , netcoreSdkVersion , propertiesToAdd , itemsToAdd , warnings ) ;
289
289
}
290
290
291
+ /// <summary>Try to find the dotnet binary from the SDK resolution result upwards</summary>
292
+ private static string ? TryResolveDotnetExeFromSdkResolution ( SdkResolutionResult resolverResult )
293
+ {
294
+ var expectedFileName = RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? Constants . DotNetExe : Constants . DotNet ;
295
+ var currentDir = resolverResult . ResolvedSdkDirectory ;
296
+ while ( currentDir != null )
297
+ {
298
+ var dotnetExe = Path . Combine ( currentDir , expectedFileName ) ;
299
+ if ( File . Exists ( dotnetExe ) )
300
+ {
301
+ return dotnetExe ;
302
+ }
303
+
304
+ currentDir = Path . GetDirectoryName ( currentDir ) ;
305
+ }
306
+
307
+ return null ;
308
+ }
309
+
291
310
private static string ? GetMSbuildRuntimeVersion ( string sdkDirectory , string dotnetRoot )
292
311
{
293
312
// 1. Get the runtime version from the MSBuild.runtimeconfig.json file
0 commit comments