简体   繁体   中英

NETSDK1045 The current .NET SDK does not support targeting .NET Core 3.1 - Caused by Cache?

My Visual Studio 2019 project seems to have lost its mind. Yesterday morning, I was able to build it and everything was great. Then, suddenly, in the afternoon, it decided to complain:

NETSDK1045 The current .NET SDK does not support targeting .NET Core 3.1. Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 3.1

It's important to note that the only changes I made over the course of the day were of a trivial nature. I didn't add any new packages, for example. I just made one little code-tweak, and that's it. It gets weirder, though.

I downloaded my Carbonite backup from the day before, but it seems to have the same problem. How is that possible, since it worked fine at that point in time?

And yet it gets stranger still, because when I opened my CS file this morning, I see this:

截图图片

And, though this didn't happen yesterday, now I suddenly have namespace errors:

命名空间错误的屏幕截图

A few important notes:

  • Yes, I rebooted
  • I have two other Azure functions projects that build just fine. They all target .NET Core 3.1.
  • I examined the .sln files and didn't see anything about this one that was any different.
  • In comparing the .csproj files, the only difference is that this one has 2 additional package references: Azure.Storage.Queues and Microsoft.Azure.WebJobs.Extensions.DurableTask . These have been there all along, though - nothing changed with them yesterday.
  • I have both VS 2017 and VS 2019 (v16.7.1) installed. Please note that my VS 2019 version 16.7.1 meets specs.
  • I followed these instructions and didn't find anything amiss with paths, no global.json, etc. I didn't expect to, since my other solutions still build fine, so whatever's wrong, it isn't system-wide but project-specific.

This is the complete ItemGroup section with all PackageReferences:

<PackageReference Include="Azure.Storage.Queues" Version="12.4.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.1.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.2" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.3" />
<PackageReference Include="Twilio" Version="5.46.0" />

Although I do see there are package updates available, my two other functions referencing the older package versions don't have this problem.

Noticing than a package update was available for Microsoft.NET.Sdk.Functions , I decided to apply it, and suddenly my solution is happy - all problems mysteriously vanished - and yet my other functions that rely on the older 3.0.3 package still build just fine.

Why did it continue to have this problem even after reverting to my code from the day before when the problem didn't even exist? Why is it that this solution, and only this solution, suddenly decided that was going to quit working and need the new package version? Or was it not that it needed that package specifically, but rather for the installation process to "reset" or clear something?

The only possible explanation I can come up with is that something outside of the solution directory caused this, which is why restoring my backup didn't fix it.

Could this have been caused by something getting corrupted in the Visual Studio cache? Is there something else (easier) I should have done earlier in the process, like manually clear the cache? I didn't realize there was such a cache until researching this issue, so I didn't know to do that.

My experience with Visual Studio is that things like this don't usually happen just once, so I'd like to have a better idea what to do when it happens again.

PS ATTN POST REVIEWERS: While there are other questions regarding this error, if you read my post closely, you'll see that I checked pretty much everything that you can check and the answers to those questions do not provide insight to resolve this. Since restoring from backup still didn't fix this, my question is specifically about whether this could have been caused by a caching issue and whether clearing the cache should have been an early step in my process.

if you are sure that all SDKs are installed correctly, then check the global.json from your solution folder. follow this post to correct it.

it could be as simple as this:

{
  "sdk": {
    "version": "3.1.xxx"  //you have to find the exact number from SDK installed folder.
  }
}

you can also set it globally, if your environment get massed, but normally we dont need this command:

dotnet new globaljson --sdk-version 3.0.100

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