在 Visual Studio 2017 .NET Core 2.0 控制台应用程序中包含以下代码
using System;
using System.Security.Principal;
namespace smallTests
{
class Program
{
static void Main(string[] args)
{
var identity = WindowsIdentity.GetCurrent();
}
}
}
为什么我收到错误:
The name 'WindowsIdentity' does not exist in the current context
如果我可以在 .NET Core 2.0 库中看到这个类.Net Core 文档 https://learn.microsoft.com/en-us/dotnet/api/system.security.principal.windowsidentity?view=netcore-2.0 ?
相同的代码适用于 .NET 控制台应用程序。
[EDIT]
@威尔@JohnnyL评论说我不参考,System.Security.Principal.Windows.dll
, 那是真实的。
但我很好奇为什么它不起作用,因为
在.NET 4.6.1项目中(其中类WindowsIdentity可见)我也不引用这个System.Security.Principal.Windows.dll
具体来说。不过我指的是System.dll。
我一直认为它的工作原理类似于命名空间层次结构。例如,当我提到
System.Security.Principal.dll
我可以使用其中的课程
System.Security.Principal.Windows.dll
.
我错了吗?
I added System.Security.Principal.dll
手动到.NetCore解决方案,但它仍然不起作用。
[EDIT2]
@Will非常感谢您对这个主题的解释,它对我帮助很大。
我试图弄清楚 WindowsIdentity 是否与 Core 兼容,看起来是这样,请参阅:
in this apisof.net https://apisof.net/catalog/System.Security.Principal.WindowsIdentity在声明区域我可以看到 WindowsIdentity 位于.Net Core 2.0 System.Security.Principal.Windows, Version=4.1.1.0, PublicKeyToken=b03f5f7f11d50a3a
但是我没有System.Security.Principal.Windows.dll
在参考文献中,我应该添加它吗?如果是的话从哪里来?
in 我在列表中看到这个类(如果它与核心不兼容,该列表的目的是什么?
我还找到了有关该课程的信息那个链接 https://source.dot.net/#System.Security.Principal.Windows/System/Security/Principal/WindowsIdentity.cs,200d683bfb324fda
我是不是找错地方了?