简体   繁体   English

NETSDK1045 当前的 .NET SDK 不支持面向 .NET Core 3.1 - 由缓存引起?

[英]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.我的 Visual Studio 2019 项目似乎失去了理智。 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.我从前一天下载了我的 Carbonite 备份,但它似乎有同样的问题。 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:然而它变得更奇怪了,因为当我今天早上打开我的 CS 文件时,我看到了这个:

截图图片

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.我还有两个其他 Azure 函数项目构建得很好。 They all target .NET Core 3.1.它们都针对 .NET Core 3.1。
  • I examined the .sln files and didn't see anything about this one that was any different.我检查了.sln文件,并没有看到与此文件有任何不同的任何内容。
  • 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 .在比较.csproj文件时,唯一的区别是这个文件有 2 个额外的包引用: Azure.Storage.QueuesMicrosoft.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.我安装了 VS 2017 和 VS 2019 (v16.7.1)。 Please note that my VS 2019 version 16.7.1 meets specs.请注意,我的 VS 2019 版本 16.7.1 符合规范。
  • 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.我按照这些说明操作,没有发现路径有任何问题,没有 global.json 等。我没想到,因为我的其他解决方案仍然可以正常构建,所以无论有什么问题,它都不是系统范围的,而是项目-具体的。

This is the complete ItemGroup section with all PackageReferences:这是包含所有 PackageReferences 的完整 ItemGroup 部分:

<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.注意到Microsoft.NET.Sdk.Functions有可用的包更新,我决定应用它,突然间我的解决方案很高兴 -所有问题都神秘地消失了- 而我依赖于旧 3.0.3 包的其他功能仍在构建正好。

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?这可能是由于 Visual Studio 缓存中的某些内容损坏造成的吗? 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.我使用 Visual Studio 的经验是,这样的事情通常不会只发生一次,所以我想更好地了解当它再次发生时该怎么做。

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. PS ATTN 帖子审阅者:虽然还有关于此错误的其他问题,但如果您仔细阅读我的帖子,您会发现我检查了您可以检查的几乎所有内容,而这些问题的答案并没有提供解决此问题的见解。 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.如果您确定所有 SDK 都已正确安装,请检查您的解决方案文件夹中的global.json 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无效 - 错误 NETSDK1045:当前 .NET SDK 不支持定位 .NET 6.0 - None worked - Error NETSDK1045: The current .NET SDK does not support targeting .NET 6.0 gitlab CI 中的 ASP.NET 核心项目构建错误:错误 NETSDK1045:当前 .NET SDK 不支持面向 .NET Core 5.0 - ASP.NET core project build error in gitlab CI : error NETSDK1045: The current .NET SDK does not support targeting .NET Core 5.0 使用 Blazor Asp.NetCore 托管模板时获取“NETSDK1045 当前 .NET SDK 不支持 .NET Core 3.0 作为目标” - Getting “NETSDK1045 The current .NET SDK does not support .NET Core 3.0 as a target” when using Blazor Asp.NetCore hosted template 当前的 .NET SDK 不支持面向 .NET Core 2.2 - The current .NET SDK does not support targeting .NET Core 2.2 当前的.NET SDK不支持定位.NET Core 2.2。 (SDK 2.2.202) - The current .NET SDK does not support targeting .NET Core 2.2. (SDK 2.2.202) 当前的 .NET SDK 不支持针对 .NET Core 2.1。 目标 .NET Core 1.1 或更低版本 - The current .NET SDK does not support targeting .NET Core 2.1. Either target .NET Core 1.1 or lower 错误:当前的.NET SDK不支持定位.NET Standard 2.0 - Error: The current .NET SDK does not support targeting .NET Standard 2.0 MIP SDK 1.7.133 .NET Core 3.1 支持 - MIP SDK 1.7.133 .NET Core 3.1 support Azure 构建管道 NuGet 还原错误 NETSDK1045 - Azure build pipeline NuGet Restore error NETSDK1045 警告 NETSDK1080:面向 .NET Core 3.0 或更高版本时,不需要对 Microsoft.AspNetCore.App 的 PackageReference - warning NETSDK1080: A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting .NET Core 3.0 or higher
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM