安装 .NET Standard 2.1

huangapple go评论62阅读模式
英文:

Install .NET standard 2.1

问题

尝试在我的Windows 10系统中打开C#项目,使用的是Visual Studio 2019。项目是用.NET Standard 2.1创建的,但似乎不受我的系统支持:

> 错误 NU1201
> 项目App与uap10.0.16299 (UAP, Version=v10.0.16299) / win10-x64-aot不兼容。
> 项目App支持:netstandard2.1 (.NETStandard, Version=v2.1) App.UWP

如果我降级到.NET Standard 2.0,我遇到了其他问题

如何解决这个问题?如何在我的系统上安装.NET Standard 2.1?

英文:

Trying to open C# project in my Windows 10 system, Visual Studio 2019. Project is created with .NET Standard 2.1, but looks like it is not supported in my system:

> Error NU1201
> Project App is not compatible with uap10.0.16299 (UAP, Version=v10.0.16299) / win10-x64-aot.
> Project App supports: netstandard2.1 (.NETStandard, Version=v2.1) App.UWP

If I downgrade to .NET Standard 2.0, I'm getting other problems.

How to solve this problem? How to install .NET Standard 2.1 on my system?

答案1

得分: 2

你需要安装 .NET Core 3(或更高版本)以获得 .NET Standard 2.1 的功能。

在撰写本文时,我建议使用 .NET 6 或更高版本。.NET 的发布和支持(.NET 5+ 和 .NET Core)

对于开发,你需要的是 SDK,而不仅仅是运行时。

英文:

You need to install .NET Core 3 (or later) for .NET Standard 2.1 capabilities.

At the time of writing, I suggest .NET 6 or later. Releases and support for .NET (.NET 5+ and .NET Core).

For development, you will want the SDK, not just the runtime.

答案2

得分: 2

错误消息中的 App.UWP 提示我这是一个 UWP 应用程序,但与 .NET Standard 2.1 不兼容。

可能的解决方案:

  • 您必须在引用的项目中将目标设置为 .NET Standard 2.0。如果您的 UWP 项目至少目标 Windows 10.0.16299.0(秋季创作者更新,版本 1709),则可以使用这样的依赖库。但正如您注意到的,.NET Standard 2.0 支持的 API 比 .NET Standard 2.1 少得多。
  • 另一种解决方案是将应用程序项目类型更改为更现代的项目类型,如 WinUI 3 或 MAUI。如果您只想面向 Windows,那么 WinUI 项目可能是最简单的解决方案(也许您甚至可以在不对 UWP 应用程序进行任何更改的情况下重用您的视图和视图模型)。如果需要至少 .NET 5 和 Windows 10.0.17763.0(2018 年 10 月发布,版本 1809),这是推荐的解决方案。但坦率地说,我认为这在今天不是一个真正的障碍。

在以下链接中查看相同演示应用程序的几个示例:UWPWinUI。UWP 版本之所以能够工作,是因为所引用包的依赖项都支持 .NET Standard 2.0,正如在其 README 选项卡中强调的一样。

英文:

The App.UWP in the error message gives me the hint that this is a UWP app, which simply isn't compatible with .NET Standard 2.1.

Possible solutions:

  • You must target .NET Standard 2.0 in your referenced project. UWP projects are able to use such a dependent library if you target at least Windows 10.0.16299.0 (Fall Creators Update, version 1709). But as you noticed, .NET Standard 2.0 supports much less API than .NET Standard 2.1
  • Another solution if you change your application project type to a more modern one such as WinUI 3 or MAUI. If you want to target Windows only, then a WinUI project can be the simplest solution (maybe you can even reuse your views and view models without any change created for the UWP app). This is the recommended solution if it's not a problem that it requires to target at least .NET 5 and Windows 10.0.17763.0 (October 2018 release, version 1809). But frankly, I don't think this is a real barrier today.

See a couple of examples for the same demo application in UWP and WinUI behind the links. The UWP one can work only because the dependencies of the referenced package all support .NET Standard 2.0 as it's emphasized on its README tab.

huangapple
  • 本文由 发表于 2023年5月20日 22:14:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76295666.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定