You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Nested dotnet build fails to load NuGet task with .NET SDK 10.0.400 #14699
After updating to .NET SDK 10.0.400, complog tests fail when a test fixture launches a nested dotnet build.
/usr/share/dotnet/sdk/10.0.400/NuGet.targets(458,5): error MSB4062:
The "NuGet.Build.Tasks.GetRestoreSolutionProjectsTask" task could not be loaded from
/usr/share/dotnet/sdk/10.0.400/NuGet.Build.Tasks.dll.
Could not load type 'Microsoft.Build.Framework.IMultiThreadableTask' from assembly
'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a'.
changed the title [-]Nested dotnet invocations inherit unsafe MSBuild environment state[/-][+]Nested dotnet build fails to load NuGet task with .NET SDK 10.0.400[/+]on Aug 13, 2026
The complog test fixture creates a temporary global.json requesting:
version: 10.0.100
The runner already has a compatible 10.0.110 SDK installed
The nested dotnet build selects that older 10.0.110 SDK.
It still inherits MSBuildExtensionsPath pointing to 10.0.400.
The 10.0.400 NuGet task now implements IMultiThreadableTask , but this interface does not exist in MSBuild 18.0.11 from SDK 10.0.111. This is why we now get MSB4062.
(One initially confusing detail is that the error mentions GetRestoreSolutionProjectsTask , but this task does not implement IMultiThreadableTask in the shipped 10.0.400 source.)
The similar issue was already discovered in 2023, but it was fixed only on the client side in complog. That workaround removed MSBuildSDKsPath from the child environment.
After that issue, MSBuild diagnostics were improved:
But as far as I can see, the SDK-mixing behaviour itself was not addressed at the product level. Do we know why it was treated only as a complog/client-side issue in 2023?
Should we continue treating this as the responsibility of clients that launch nested dotnet processes? Or should we address it at the SDK/MSBuild level so SDK-generated paths from the outer invocation do not override the SDK selected by the nested invocation?
BTW Jared already fixed iton the client side by filtering child env.
If this is expected from client it also should be documented? I was not able to find documentation saying that callers launching nested dotnet commands must remove inherited MSBuildSDKsPath and MSBuildExtensionsPath.
The dotnet CLI currently sets MSBuildExtensionsPath and MSBuildSDKsPath for every MSBuild invocation.
The team’s initial reaction was that this is likely the wrong model: when the correct Microsoft.Build.dll /toolset is selected, MSBuild should be able to derive its own paths.
These variables have been set for many years, possibly to support non-standard SDK layouts, testing, or in-process evaluation, but no clear current requirement was identified in the thread.
Similar behavior exists in MSBuildLocator. Experiments there passed from SDK 2.1.300 through .NET 10—including restore, builds, and worker nodes—with MSBUILD_EXE_PATH , MSBuildSDKsPath , and MSBuildExtensionsPath unset.
Stale values are actively dangerous because they can override normal engine/toolset discovery and leak into nested processes.
Conclusion: the preferred direction is for the SDK/CLI to stop passing these generated MSBuild paths as ambient environment state and let the selected engine/toolset determine them. This would also avoid leaking the values into nested dotnet processes.
There was not yet a final design decision on whether the CLI should forcibly unset these variables for every invocation or simply stop setting/overriding them. We still need to validate explicit user overrides, non-standard layouts, and in-process evaluation. No implementation owner or release target was agreed, and changing this for .NET 11 was considered risky
Nested dotnet invocations inherit MSBuildSDKsPath / MSBuildExtensionsPath from the parent, which can mix SDK components. We lean toward the CLI unsetting/not setting those variables and letting MSBuild discover its toolset, but Native AOT CLI scenarios may lack the runtime location metadata needed for that.
Next action: The proposed investigation is whether the CLI can stop setting—or explicitly unset—these variables and let the selected MSBuild toolset determine its own paths. We need to verify managed CLI builds, Native AOT real builds and in-process evaluation, uses of AppContext.BaseDirectory , nonstandard SDK layouts, and intentional user overrides.
Grooming: Too risky to stop setting the env vars this late in .NET 11. AOT SDK currently depends on some of those for the NAOT msbuild path resolution.
@ViktorHofer I think we could stop setting the env vars if we wanted - but we need to document/understand how that impacts NAOT apps and NAOT libraries, and make a plan for filling those gaps to unblock the SDK work.
Here are the findings from my digging into the current codebase:
For a generic Native AOT host, the contract should be: select one complete, matching MSBuild ToolsetRoot before touching any MSBuild API.
Native AOT executable
The executable can obtain ToolsetRoot in either way:
Side-by-side deployment: Place the complete MSBuild toolset beside the native executable. AppContext.BaseDirectory can then identify the root, provided it contains MSBuild.dll.
Explicit configuration: Resolve ToolsetRoot from an argument, configuration, or installation lookup.
Before initialization, handle inherited MSBuildSDKsPath and MSBuildExtensionsPath* as intentional overrides or remove them. Otherwise they can replace paths derived from ToolsetRoot.
Native AOT library
Why libraries should not use AppContext.BaseDirectory to locate the ToolsetRoot
For a Native AOT library, AppContext.BaseDirectory belongs to the host application, not the loaded library. If the host directory happens to contain another MSBuild.dll, fallback discovery could silently select an incompatible toolset.
A library should therefore require explicit initialization rather than permitting base-directory discovery.
It should be process-wide, thread-safe, and fail if MSBuild has already initialized or a different root was previously selected.
With that contract, neither Native AOT executables nor libraries need to depend on ambient SDK-generated path variables or accidental AppContext.BaseDirectory contents.
NativeAOT is a known scenario. I'm also worried about the unknown ones. Changing in .NET 12 P1 and collecting feedback up to GA sounds like a better plan to me.
Activity
[-]Nested dotnet invocations inherit unsafe MSBuild environment state[/-][+]Nested dotnet build fails to load NuGet task with .NET SDK 10.0.400[/+]OvesN commentedon Aug 13, 2026
I was investigating the issue reported by Jared here
I think the task migration only revealed an already existing problem (or feature?):
In our concrete case when it failed
dotnet testtherefore runs under 10.0.400.version: 10.0.100
dotnet buildselects that older 10.0.110 SDK.The 10.0.400 NuGet task now implements IMultiThreadableTask , but this interface does not exist in MSBuild 18.0.11 from SDK 10.0.111. This is why we now get MSB4062.
(One initially confusing detail is that the error mentions GetRestoreSolutionProjectsTask , but this task does not implement IMultiThreadableTask in the shipped 10.0.400 source.)
The similar issue was already discovered in 2023, but it was fixed only on the client side in complog. That workaround removed MSBuildSDKsPath from the child environment.
After that issue, MSBuild diagnostics were improved:
[Feature Request]: Log the results of SDK resolution through a Logger · Issue #9413 · dotnet/msbuild
But as far as I can see, the SDK-mixing behaviour itself was not addressed at the product level. Do we know why it was treated only as a complog/client-side issue in 2023?
Should we continue treating this as the responsibility of clients that launch nested dotnet processes? Or should we address it at the SDK/MSBuild level so SDK-generated paths from the outer invocation do not override the SDK selected by the nested invocation?
BTW Jared already fixed iton the client side by filtering child env.
If this is expected from client it also should be documented? I was not able to find documentation saying that callers launching nested dotnet commands must remove inherited MSBuildSDKsPath and MSBuildExtensionsPath.
OvesN commentedon Aug 14, 2026
From discussion with the team:
Conclusion: the preferred direction is for the SDK/CLI to stop passing these generated MSBuild paths as ambient environment state and let the selected engine/toolset determine them. This would also avoid leaking the values into nested dotnet processes.
There was not yet a final design decision on whether the CLI should forcibly unset these variables for every invocation or simply stop setting/overriding them. We still need to validate explicit user overrides, non-standard layouts, and in-process evaluation. No implementation owner or release target was agreed, and changing this for .NET 11 was considered risky
OvesN commentedon Aug 19, 2026
Nested dotnet invocations inherit MSBuildSDKsPath / MSBuildExtensionsPath from the parent, which can mix SDK components. We lean toward the CLI unsetting/not setting those variables and letting MSBuild discover its toolset, but Native AOT CLI scenarios may lack the runtime location metadata needed for that.
Next action: The proposed investigation is whether the CLI can stop setting—or explicitly unset—these variables and let the selected MSBuild toolset determine its own paths. We need to verify managed CLI builds, Native AOT real builds and in-process evaluation, uses of AppContext.BaseDirectory , nonstandard SDK layouts, and intentional user overrides.
ViktorHofer commentedon Aug 19, 2026
Grooming: Too risky to stop setting the env vars this late in .NET 11. AOT SDK currently depends on some of those for the NAOT msbuild path resolution.
baronfel commentedon Aug 19, 2026
@ViktorHofer I think we could stop setting the env vars if we wanted - but we need to document/understand how that impacts NAOT apps and NAOT libraries, and make a plan for filling those gaps to unblock the SDK work.
baronfel commentedon Aug 19, 2026
Here are the findings from my digging into the current codebase:
For a generic Native AOT host, the contract should be: select one complete, matching MSBuild
ToolsetRootbefore touching any MSBuild API.Native AOT executable
The executable can obtain
ToolsetRootin either way:AppContext.BaseDirectorycan then identify the root, provided it containsMSBuild.dll.ToolsetRootfrom an argument, configuration, or installation lookup.Before initialization, handle inherited
MSBuildSDKsPathandMSBuildExtensionsPath*as intentional overrides or remove them. Otherwise they can replace paths derived fromToolsetRoot.Native AOT library
Why libraries should not use
AppContext.BaseDirectoryto locate the ToolsetRootFor a Native AOT library,
AppContext.BaseDirectorybelongs to the host application, not the loaded library. If the host directory happens to contain anotherMSBuild.dll, fallback discovery could silently select an incompatible toolset.A library should therefore require explicit initialization rather than permitting base-directory discovery.
Proposed engine API
Initialization would derive:
CurrentMSBuildExePath=<ToolsetRoot>/MSBuild.dllMSBuildToolsPath=ToolsetRootMSBuildSDKsPath=<ToolsetRoot>/SdksMSBuildExtensionsPath*=ToolsetRootIt should be process-wide, thread-safe, and fail if MSBuild has already initialized or a different root was previously selected.
With that contract, neither Native AOT executables nor libraries need to depend on ambient SDK-generated path variables or accidental
AppContext.BaseDirectorycontents.ViktorHofer commentedon Aug 19, 2026
NativeAOT is a known scenario. I'm also worried about the unknown ones. Changing in .NET 12 P1 and collecting feedback up to GA sounds like a better plan to me.
ViktorHofer commentedon Aug 25, 2026
Possibly related issue a customer reported: #14742
JanProvaznik commentedon Sep 17, 2026
another report dotnet/aspnetcore#69286
do we have any recommendation?