RegistryKey可以在ASP.NET Core 2.0应用程序中引用,但不能在Console .NET 2.0 Core应用程序中引用

bur*_*1ce 2 .net-core asp.net-core visual-studio-2017

我可以在ASP.NET Core 2.0应用程序中引用RegistryKey类,但不能在Console .NET 2.0 Core App中引用.这是为什么?

当我尝试在RegistryKey中引用OpenBaseKey()(静态方法)时,我收到以下编译错误.

The name 'RegistryKey' does not exist in the current context    
Run Code Online (Sandbox Code Playgroud)

我正在使用VS2017,我的项目是针对.NET Core 2.0(不是标准2.0).

Tse*_*eng 8

可能您的ASP.NET核心应用程序的目标是.NET Framework,而不是.NET Core.添加所需的NuGet包以获取Registry API.

这是Microsoft.Win32.Registry(这里).但是你失去了可移植性,无法在Linux和MacOS上运行应用程序.