54

I've just downloaded the release version of .NET Core 3.0.100
It was installed alongside older version that I have:

enter image description here

When I try to run dotnet restore for a project that targets .NET Core 3 (<TargetFramework>netcoreapp3.0</TargetFramework>), I get this error

C:\Program Files\dotnet\sdk\2.2.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.0.  Either target .NET Core 2.2 or lower, or use a version of the .NET SDK that supports .NET Core 3.0.

I have a global.json file that explicitly states that I need the 3.0.100 SDK

{
  "sdk": {
    "version": "3.0.100"
  }
}

I know that I can edit the MSBuildSDKsPath env variable to point to the 3.0.100 SDK, and it works, but I don't want to do it, I have other projects on my machine that still need to use older versions of .NET Core.

Is there a way to make the dotnet tool use the SDK that's stated in global.json instead of the one in MSBuildSDKsPath?

Edit: I use Visual Studio Code

3
  • 2
    The great thing about having a standard .NET library, is that there are so many standards to choose from.
    – Ian Boyd
    Commented May 11, 2020 at 20:23
  • Did my answer solve your problem? Commented May 19, 2020 at 6:30
  • Not a complete answer, but when I got this error, deleting all my bin, obj, internal build outputs, and .vs folders and then rebuilding made the error go away. (Build clean was failing.) I first got the error after trying to add new items to my project and it didn't go away when I removed them. Commented Jun 14, 2021 at 20:00

4 Answers 4

86

You also have to update your visual studio to the minimum supported version:

.NET Core 3.0

  • minimum visual studio v16.3

.NET Core 3.1

  • minimum visual studio v16.5

.NET Core 5.0

  • minimum visual studio v16.6 latest preview

.NET Core 6.0

  • minimum visual studio v17.0 latest preview

enter image description here

(https://dotnet.microsoft.com/download/dotnet-core/3.0)


![enter image description here

(https://dotnet.microsoft.com/download/dotnet-core/3.1)


enter image description here

(https://dotnet.microsoft.com/download/dotnet/5.0)


enter image description here

(https://dotnet.microsoft.com/download/dotnet/6.0)

9
  • Did you solve it? Maybe there is also an update for vscode needed Commented Sep 25, 2019 at 6:07
  • 1
    I was having this problem with VS CODE. I updated VISUAL STUDIO to v16.3 and now VS Code is working properly. If you read through the error listing in VS Code, it references Visual Studio. That was my clue. Updated Visual Studio and all is good.
    – Steve G
    Commented Nov 27, 2019 at 0:10
  • 4
    This answer is also relevant to users of Azure DevOps as a CI platform. The build agent (hosted or on-prem) needs to have access to the appropriate install of VS 2019 and using the appropriate dotnet tools version to build 3.0/3.1 projects.
    – Josh Gust
    Commented Feb 13, 2020 at 22:36
  • 5
    This solved the issue for me. Had the problem in a azure devops pipeline, and changing my build agent from a vs17 to 19 solved the problem. Thanks!
    – Danie
    Commented Mar 11, 2020 at 22:10
  • 2
    When you are installing preview versions of .NET, ensure that 'Use previews of .NET Core SDK' is checked (Tools -> Options -> Preview Features) Commented Apr 17, 2021 at 5:45
1

I got this error in Azure DevOps with .NET 6:

error NETSDK1045: The current .NET SDK does not support targeting .NET 6.0. Either target .NET 5.0 or lower, or use a version of the .NET SDK that supports .NET 6.0.

enter image description here

Solved by including the SDK like this:

steps:
- task: UseDotNet@2
  displayName: 'Install .NET 6 SDK'
  inputs:
    version: 6.0.x
    performMultiLevelLookup: true

https://learn.microsoft.com/en-us/azure/devops/pipelines/ecosystems/dotnet-core?view=azure-devops&tabs=dotnetfive#build-environment

Github thread about the issue:

https://github.com/dotnet/core/issues/6907

0

Issues will be resolved going through below are the checklist

  1. Environment Variable (Set it to Root folder) for ex. C:/Program Files/DotNet as PATH variable - Reboot to get changes affected

  2. Check Visual Studio Version

  3. Run dotnet --info to check SDKs are already installed

  4. Delete MSBuildSDKPath if it is set in Environment Variables

0

I had the same error when trying to build a solution using JetBrains Rider. The problem turned out to be Rider using wrong msbuild.exe. It was auto-detecting 2017 version instead of 2019. I had to manually adjust it in JetBrains settings in File | Settings | Build, Execution, Deployment | Toolset and Build. See more details here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.