找不到命名空间Microsoft.Win32 [英] Namespace Microsoft.Win32 could not be found

查看:516
本文介绍了找不到命名空间Microsoft.Win32的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我昨天安装了Visual Studio并迈出了第一步。我想看看安装了哪个版本的.NET Framework,所以我遵循了Microsoft的代码:https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine -which-versions-are-installed#to-find-net-framework-versions-by-querying-the-registry-in-code-net-framework-45-and-later
(向下滚动一下代码)。我用'Console App(.NET Core)'打开了一个新的Visual C#项目,并将给定的代码复制到其中。

I installed Visual Studio yesterday and taking my first steps. I would like to see what version of the .NET Framework is installed, so I followed this code from Microsoft: https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed#to-find-net-framework-versions-by-querying-the-registry-in-code-net-framework-45-and-later (scroll a bit down for the code). I opened a new Visual C# project with 'Console App (.NET Core)' and copied the given code in it.

在编辑器中,' RegistryKey'发出错误:找不到命名空间。 "使用Microsoft.Win32;"这一行是灰色的,就像在代码中没有调用它一样。

In the editor, the 'RegistryKey' is giving an error: Namespace cannot be found. The line 'using Microsoft.Win32;' is grey as if it is not called upon in the code.

当我查看"解决方案资源管理器"面板时,我可以列出依赖项。我没有看到MicrosoftWin32.dll,但我确实看到了mscorlib.dll。我在那里读到可以在那里找到Microsoft.Win32命名空间的地方?

When I look in the Solution Explorer panel, I can list the dependencies. I do not see MicrosoftWin32.dll but I do see mscorlib.dll. I read somewhere that the Microsoft.Win32 namespace could be found there?

有人可以给我一些线索,如何解决这个问题?我在哪里可以找到Microsoft.Win32命名空间?为什么在此标准项目中不可用?

Can someone give me some clues as how to resolve this? Where can I find Microsoft.Win32 namespace? Why is it not available in this standard project?

推荐答案

因为.Net核心不支持特定于平台的API,如Microsoft.Win32。  

because.Net core does not support platform-specific APIs like Microsoft.Win32. 

您可以通过这种方式重构代码

You can refactor your code this way


  • a .Net核心库
  • 基于.Net Framework的Win32控制台项目,您可以使用Registry类
  • 基于Mono的Linux控制台项目,该项目在Linux上实现了Microsoft.Win32.Registry


这篇关于找不到命名空间Microsoft.Win32的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆