Skip to content

Nested dotnet build fails to load NuGet task with .NET SDK 10.0.400 #14699

Open

Description

@OvesN

Description

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'.

Reproduction

Failure log:

Activity

  1. self-assigned this
    on Aug 13, 2026
  2. 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
  3. OvesN commented on Aug 13, 2026

    @OvesN
    ContributorAuthor

    I was investigating the issue reported by Jared here

    I think the task migration only revealed an already existing problem (or feature?):

    1. An outer dotnet /MSBuild invocation uses SDK A and sets SDK-specific environment paths.
    2. Code inside that build starts another process without cleaning the environment.
    3. That process launches another dotnet  command.
    4. The new command selects a different SDK B, usually because of another global.json 
    5. Some paths from SDK A are still inherited, so components from A and B are mixed. The issue becomes visible when those components are incompatible.

    In our concrete case when it failed

    1. GitHub Actions installs/uses SDK 10.0.400.
    2. dotnet test therefore runs under 10.0.400.
    3. The complog test fixture creates a temporary global.json requesting:
           version: 10.0.100
    4. The runner already has a compatible 10.0.110 SDK installed
    5. The nested dotnet build selects that older 10.0.110 SDK.
    6. 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:

    [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.

  4. OvesN commented on Aug 14, 2026

    @OvesN
    ContributorAuthor

    From discussion with the team:

    • 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

  5. OvesN commented on Aug 19, 2026

    @OvesN
    ContributorAuthor

    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.

  6. ViktorHofer commented on Aug 19, 2026

    @ViktorHofer
    Member

    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.

  7. baronfel commented on Aug 19, 2026

    @baronfel
    Member

    @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.

  8. baronfel commented on Aug 19, 2026

    @baronfel
    Member

    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.

    Proposed engine API

    MSBuildHost.Initialize(new MSBuildHostOptions
    {
        ToolsetRoot = toolsetRoot
    });

    Initialization would derive:

    • CurrentMSBuildExePath = <ToolsetRoot>/MSBuild.dll
    • MSBuildToolsPath = ToolsetRoot
    • MSBuildSDKsPath = <ToolsetRoot>/Sdks
    • MSBuildExtensionsPath* = ToolsetRoot

    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.

  9. ViktorHofer commented on Aug 19, 2026

    @ViktorHofer
    Member

    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.

  10. ViktorHofer commented on Aug 25, 2026

    @ViktorHofer
    Member

    Possibly related issue a customer reported: #14742

  11. JanProvaznik commented on Sep 17, 2026

    @JanProvaznik
    Member

    another report dotnet/aspnetcore#69286

    do we have any recommendation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions