简体   繁体   中英

Getting “NETSDK1045 The current .NET SDK does not support .NET Core 3.0 as a target” when using Blazor Asp.NetCore hosted template

I've installed the preview of .NetCore 3.0 and tried to run the blazor template Blazor (ASP.NET Core hosted) in Visual Studio 2019:

在此处输入图片说明

The error that occured, was the following:

NETSDK1045 The current .NET SDK does not support .NET Core 3.0 as a target. Either target .NET Core 2.2 or lower, or use a .NET SDK version that supports .NET Core 3.0.

During these days I had to overcome this issue on a number of different development machines/containers: eventually, I found no less than 6 different reasons that could cause this kind of error:

  1. Missing .NET Core 3 SDK (x86 or x64)
  2. .NET Core SDK preview support not enabled in VS2019
  3. VS2017 instead of VS2019
  4. Wrong SDK path in PATH environment variable(s)
  5. Wrong SDK path in MSBuildSDKsPath environment variable(s)
  6. Wrong SDK version in the project's global.json file

The workarounds for those scenarios are pretty easy to understand, you basically have to either install the proper SDK or remove the "offending" SDK reference(s). However, I did my best to document them all in this post on my blog.

Following this comment , I managed to resolve the problem by installing the x86 version of the .NET Core 3.0 additionally to the x64 version. The build worked after restarting Visual Studio (2019).

for me the solution was removing a path variable MSBuildSDKsPath - Because of exploring preview sdks's i at some point declared that variable to fix another sdk bug - seems like that force sets the used version. So in my case it was set to 3.0.100 and resulted in errors when attempting to use 3.1.300

I got the same error and resolve it with checking the option "Use previews of the .NET Core SDK (requires restart)". Open Tools > Options and try looking at "Preview Features" or ".Net Core" depending of your Visual Studio version. Watch out of VS updates, they can disable it.

This is a very hacky-feeling solution but at least it worked. Let's say you've installed the SDK for 3.0.100-rc1-014190. It shows up in dotnet --list-sdks as expected but still doesn't seem to be detected by Visual Studio, and you get the same NETSDK1405 error when trying to build or test anything from the dotnet CLI.

Look in your dotnet SDK install directory (usually C:\\Program Files\\dotnet\\sdk ). You should see your preview SDK in there. Either create a copy or rename the existing folder to remove the preview version suffix. For example 3.0.100-rc1-014190 would instead become 3.0.100 , like so:

在此处输入图片说明

Doing this made .Net Core 3 preview support finally work in VS2019 Preview 4 and the dotnet CLI for me.

For me it was as simple as enabling the preview in Visual Studio 2019. Unfortunately most posts that show how to do this are I believe out of date. I finally came across this stack overflow post How to enable .NET Core 3 preview SDK in VS2019? They moved the check box and it was not on by default for me.

This was a frustrating issue to track down and after doing all of the updates to VS and still not being able to install I tracked it down to an environment variable. Try removing MSBuildSDKsPath and see if that fixes your issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM