From bfba4b1a707dd82e44d74cd70b589b3e8e69fcfb Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Mon, 2 Feb 2026 14:21:11 +0100 Subject: [PATCH] Respect NetCoreSdkRoot property in TaskHostParameters The property got added with https://github.com/dotnet/sdk/commit/e0c4dda2e07d99203f83254b7ff5d117fb8e2220 The RuntimeIdentifierGraphPath property is incorrect to use as customers set that to a custom .json file in certain scenarios (i.e. new RID). --- .../TaskFactories/AssemblyTaskFactory.cs | 20 ++++++++++++++----- src/Build/Resources/Constants.cs | 5 +++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Build/Instance/TaskFactories/AssemblyTaskFactory.cs b/src/Build/Instance/TaskFactories/AssemblyTaskFactory.cs index 5c4478317d0..fd5f910b0b8 100644 --- a/src/Build/Instance/TaskFactories/AssemblyTaskFactory.cs +++ b/src/Build/Instance/TaskFactories/AssemblyTaskFactory.cs @@ -656,20 +656,30 @@ private static TaskHostParameters AddNetHostParamsIfNeeded( } string dotnetHostPath = getProperty(Constants.DotnetHostPathEnvVarName)?.EvaluatedValue; - string ridGraphPath = getProperty(Constants.RuntimeIdentifierGraphPath)?.EvaluatedValue; + string netCoreSdkRoot = getProperty(Constants.NetCoreSdkRoot)?.EvaluatedValue?.TrimEnd('/', '\\'); - if (string.IsNullOrEmpty(dotnetHostPath) || string.IsNullOrEmpty(ridGraphPath)) + // The NetCoreSdkRoot property got added with .NET 11, so for earlier SDKs we fall back to the RID graph path + if (string.IsNullOrEmpty(netCoreSdkRoot)) { - return currentParams; + string ridGraphPath = getProperty(Constants.RuntimeIdentifierGraphPath)?.EvaluatedValue; + if (!string.IsNullOrEmpty(ridGraphPath)) + { + netCoreSdkRoot = Path.GetDirectoryName(ridGraphPath); + } } - string msBuildAssemblyPath = Path.GetDirectoryName(ridGraphPath) ?? string.Empty; + // Both DOTNET_HOST_PATH and NetCoreSdkRoot are required to launch .NET task host. + // If both are not present, return the original parameters. + if (string.IsNullOrEmpty(dotnetHostPath) || string.IsNullOrEmpty(netCoreSdkRoot)) + { + return currentParams; + } return new TaskHostParameters( runtime: currentParams.Runtime, architecture: currentParams.Architecture, dotnetHostPath: dotnetHostPath, - msBuildAssemblyPath: msBuildAssemblyPath); + msBuildAssemblyPath: netCoreSdkRoot); } /// diff --git a/src/Build/Resources/Constants.cs b/src/Build/Resources/Constants.cs index 7d439a637c1..c1ac7f1fd1f 100644 --- a/src/Build/Resources/Constants.cs +++ b/src/Build/Resources/Constants.cs @@ -120,6 +120,11 @@ internal static class Constants /// internal const string RuntimeIdentifierGraphPath = nameof(RuntimeIdentifierGraphPath); + /// + /// The project property name used to get the root of the .NET Core SDK. + /// + internal const string NetCoreSdkRoot = nameof(NetCoreSdkRoot); + /// /// Defines the name of dotnet process based on the operating system. ///