stride3d/stride · error · InvalidOperationException

Could not find a supported MSBuild toolset version…

Error message

Could not find a supported MSBuild toolset version (expected 16.0 or later)

What it means

Thrown by CheckMSBuildToolset (called from FindAndSetMSBuildVersion) when a fresh ProjectCollection has no 'Current' toolset, i.e. MSBuild assemblies loaded but no VS 2019+/modern .NET SDK toolset is registered. Without a toolset, projects cannot be evaluated or built.

Solutions

  1. Install .NET SDK 6+ (or VS 2019+) so the 'Current' toolset exists.
  2. Repair or reinstall the .NET SDK if the installation is broken/partial.
  3. Check that custom DOTNET_ROOT/MSBuildSDKSPath env vars aren't misdirecting toolset lookup.
  4. Run from a Developer Command Prompt so MSBuild environment variables resolve to the modern toolset.

Example fix

// guard with clear guidance before use
using var pc = new ProjectCollection();
if (pc.GetToolset("Current") is null)
    throw new InvalidOperationException("Install .NET SDK 6+ or VS2019+ to get the 'Current' MSBuild toolset.");
Defensive patterns

Strategy: try-catch

Validate before calling

using var pc = new Microsoft.Build.Evaluation.ProjectCollection();
bool ok = pc.GetToolset("Current") != null;
if (!ok) throw new InvalidOperationException("MSBuild 'Current' toolset missing; install .NET SDK 6+ or VS2019+.");

Try / catch

try { PackageSessionPublicHelper.FindAndSetMSBuildVersion(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("toolset"))
{
    // prompt the user to repair/install the .NET SDK
}

Prevention

When it happens

Trigger: ProjectCollection.GetToolset("Current") returns null — typically because only a legacy MSBuild toolset (pre-16.0) is installed or the .NET SDK's toolsets directory isn't discoverable.

Common situations: Machine with old Build Tools 15 only; broken/missing .NET SDK install where toolsets (Current/16.0 folders) are absent; custom DOTNET_ROOT pointing to an incomplete install.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/079376594e3dd721. Report an issue: GitHub.

Appendix: source

Thrown at sources/assets/Stride.Core.Assets/PackageSessionPublicHelper.cs:131

        return s_msBuildAssemblies.Contains(assemblyName.Name, StringComparer.OrdinalIgnoreCase);
    }

    private static void SetupMSBuildCurrentHostForOutOfProc(string dotNetSdkPath)
    {
        // Workaround for https://github.com/dotnet/msbuild/pull/7013 (dotnet.exe not properly detected by MSBuild so it fallbacks to launching our own executable instead)
        var currentHostField = typeof(Microsoft.Build.Evaluation.Project).Assembly
            .GetType("Microsoft.Build.BackEnd.NodeProviderOutOfProcBase")?
            .GetField("CurrentHost", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
        currentHostField?.SetValue(null, Path.Combine(new DirectoryInfo(dotNetSdkPath).Parent.Parent.FullName, OperatingSystem.IsWindows() ? "dotnet.exe" : "dotnet"));
    }

    private static void CheckMSBuildToolset()
    {
        // Check that we can create a project
        using var projectCollection = new Microsoft.Build.Evaluation.ProjectCollection();
        if (projectCollection.GetToolset("Current") == null) // VS 2019+ (https://github.com/Microsoft/msbuild/issues/3778)
        {
            throw new InvalidOperationException("Could not find a supported MSBuild toolset version (expected 16.0 or later)");
        }
    }
}

View on GitHub (pinned to 96fad776d2)