The Current .NET SDK does not support targeting .NET Core 3.0 – Fix How to work around a common .NET Core compilation targeting error using .NET Core 3 SDK and .NET Core 3 projects with Visual Studio

The Current .NET SDK does not support targeting .NET Core 3.0 - Fix

If you came across this post it most likely mean that you’re hitting the dreadful “SDK targeting” error while trying to build, compile or upgrade a .NET Core 3 project using either Visual Studio 2017, Visual Studio 2019, the dotnet CLI or other building tools.

Here’s what the error looks like:

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

The above message could be slightly different, mostly depending on the .NET Core SDKs installed on the machine. For example, it could be any of the following:

C:\Program Files\dotnet\sdk\2.0.3\sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(135,5)
C:\Program Files\dotnet\sdk\2.2.3\sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(135,5)

… and so on.

As we can easily guess by reading the error, the problem is due to the fact that our system is trying to use the wrong .NET Core SDK (2.x) to compile a project that is targeting .NET Core 3.0. To quickly confirm that, open the <ProjectName>.csjproj project file – which is located in the project root – and check for the presence of the following line:

In this post we’ll briefly enumerate a number of workarounds that could be used to fix that issue for good.

#1. Check if .NET Core SDK 3.x is installed

This might sound stupid, but the first thing to do is to be 100% sure that there is a .NET Core SDK 3.x installed on our machine and available within our system PATH. To check this, open a command prompt and type the following command:

Once you hit Enter, you’ll see a list of .NET Core SDK installed on your machine. Ensure that there is at least a .NET Core SDK 3.x there, just like shown in the screenshot below:

The Current .NET SDK does not support targeting .NET Core 3.0 - Fix
A list of all the .NET Core SDKs installed on my development machine: they happen to be quite a lot.

If there is none, go to the official .NET Core 3 Download page and get it, then install it and try again.

If you have one (or more), check if it’s a preview release or not: if it is, such as the one in the above screenshot, go to Workaround #2: if it’s not, jump it and go to Workaround #3.

IMPORTANT: be sure to install the proper SDK architecture version  (x86/32 bit or x64/64 bit) for your given scenario.

#2. Enable .NET Core  SDKs Previews

If you’re using a .NET Core 3 preview, there’s a high chance that your issue depends on the fact that your Visual Studio installation has not been configured to use previews of the .NET Core SDK. To quickly check that, launch Visual Studio, go to Tools > Options > Environment > Preview Features and ensure that the “Use previews of the .NET Core SDK” option is enabled.

The Current .NET SDK does not support targeting .NET Core 3.0 - Fix

  • If the option is not checked, enable it, then close Visual Studio and any dotnet CLI instance/command prompt you might have opened (do not forget to do that): once done, try to compile your project again.
  • If the option is checked, or if the Preview Features element is not present, go to the next workaround.

#3. Use Visual Studio 2019

.NET Core 3.0 preview1 was the last version of .NET Core 3.0 that worked with Visual Studio 15.9 (aka Visual Studio 2017): any subsequent release of .NET Core 3.0 (including nightlies) require VS 16.0+, aka Visual Studio 2019. If you have Visual Studio 2017, install VS2019, then try again.

IMPORTANT: Visual Studio version 16.3+ is required, as previous versions (16.2 and below) would not recognize the 3.0 .NET Core SDK. Thanks to Cardi DeMonaco Jr for pointing it out!

#4. Check the PATH environment variables

Open your Control Panel, then navigate to System > Advanced System Settings > Environment Variables.

The Current .NET SDK does not support targeting .NET Core 3.0 - Fix

Once there, check the PATH variable on both the User Variables and System Variables panels and be sure that the folder referenced by the error message – for example   – is not there: in the unlikely case you find it, delete it. The only folder that you should find there is the root folder, i.e. .

#5. Check the MSBuildSDKsPath environment variable

While you are in the Environment Variables modal window, check for the presence of the MSBuildSDKsPath environment variable on both the User Variables and System Variables panels: if you find it, be sure to delete it (better) or to change it to point to your latest .NET Core 3.x SDK installation path (as shown in Workaround #1).

The Current .NET SDK does not support targeting .NET Core 3.0 - Fix

As a matter of fact, deleting that variable is usually a better approach, since the dotnet CLI will always use the most recent SDK, which will most likely be what you’ll want it to do in almost any scenario: however, you can try to explicitly set it up as a “last resort workaround”, if anything else fails (including the next workarounds).

#6. Watch out for a global.json file

Navigate to your project’s root folder and look for a global.json file: if you find one, open it with a text editor and be sure it doesn’t contain a SDK reference such as the following:

If it does, you found your culprit: delete the “sdk” key (better) or the whole global.json file (even better, assuming it doesn’t contain anything else) and try again. Alternatively, you might specify your latest .NET Core 3.0 SDK installed version (as shown in Workaround #1). Again, using a global.json file is not the best thing you can do, since you’ll prevent the dotnet CLI from automatically using the most recent SDK: however, you can try to explicitly set it up as a “last resort workaround”, if anything else fails (including the next workarounds).

For additional info regarding the global.json file usage, take a look at this page.

#7. Check for global settings

Last but not least, be sure to check that the project/solution experiencing the issue has not been created within another solution folder structure which sets the framework version globally – such as a Directory.Build.props file (thanks to Wolf for the suggestion – see comments section).

Conclusion

That’s it, at least for now: I sincerely hope that one of these workarounds will work for your scenario.

References

 

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

4 Comments on “The Current .NET SDK does not support targeting .NET Core 3.0 – Fix How to work around a common .NET Core compilation targeting error using .NET Core 3 SDK and .NET Core 3 projects with Visual Studio

  1. Visual Studio version 16.3+ is required. I had 16.2.5 and it would not recognize the 3.0 .NET Core SDK.

  2. #7 Check that you did not create the project/solution within another solution folder structure which uses something to set the framework version globally like a “Directory.Build.props” file (that was my problem)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.