Home > OS >  .NET 6 - msbuild takes wrong SDK on VS2022 for Mac
.NET 6 - msbuild takes wrong SDK on VS2022 for Mac

Time:06-27

I get an NETSDK1045 error on Visual Studio 2022 for Mac (both, Stable and 17.3 preview version) when I try to build my netcore webapp project with .NET 6.0.

Even though I set the target framework to 6.0, Visual Studio calls dotnet sdk 5.0 msbuild

/usr/local/share/dotnet/sdk/5.0.408/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(141,5): error NETSDK1045: Das aktuelle .NET SDK unterstützt .NET 6.0 nicht als Ziel. Geben Sie entweder .NET 5.0 oder niedriger als Ziel an, oder verwenden Sie eine .NET SDK-Version, die .NET 6.0 unterstützt. 0 Warnung(en) 1 Fehler

Project File:

<PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <CopyRefAssembliesToPublishDirectory>false</CopyRefAssembliesToPublishDirectory>
</PropertyGroup>

The runtimes are installed if I call dotnet on the command line:

[/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 5.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 5.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 5.0.15 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 5.0.16 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 5.0.17 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
    Microsoft.NETCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.15 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.16 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
    Microsoft.NETCore.App 5.0.17 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
    Microsoft.NETCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
    Microsoft.NETCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

as well as the SDKs

5.0.402 [/usr/local/share/dotnet/sdk]
5.0.406 [/usr/local/share/dotnet/sdk]
5.0.407 [/usr/local/share/dotnet/sdk]
5.0.408 [/usr/local/share/dotnet/sdk]
6.0.300 [/usr/local/share/dotnet/sdk]
6.0.301 [/usr/local/share/dotnet/sdk]

How can I force visual studio to call msbuild of the .net6 sdk?

CodePudding user response:

Use a global.json file

Create a file named global.json in the root of your project folder (where the solution file is or even one level above, depending on your folder structure). It's contents should be something like

{
  "sdk": {
    "version": "6.0.301"
  }
}

The version should be the SDK version you want to build with (not the runtime version).

Visual Studio may need a restart after you have created this file to work correctly.

  • Related