【问题标题】:Where to find System.DirectoryServices in ASP.NET Core 2.0?在 ASP.NET Core 2.0 中哪里可以找到 System.DirectoryServices?
【发布时间】:2017-08-22 21:44:04
【问题描述】:
我需要使用新的 ASP.NET Core 2.0 Web 应用程序运行一些 Active Directory 查询。微软的文档说 System.DirectoryServices.AccountManagement libraries are available 是 .NET Core 2.0 的一部分。
如何在 NuGet 中找到包含此命名空间的关联包?我在 NuGet 中看到的唯一一个是 Microsoft 以外的其他人不支持的库。
【问题讨论】:
标签:
asp.net-core
active-directory
nuget
asp.net-core-2.0
【解决方案1】:
我对此线程有更好的解决方案。我找到了一个名为“Microsoft.Windows.Compatibility”的 Nuget 包(它在 Pre-Release 中),它提供了您正在寻找的 System.DirectoryServices 命名空间。只需搜索 Nuget,确保选中 Pre-Release 选项,您就会找到它。一旦你得到它,大多数事情都会起作用。只需确保稍后在完成后更新包即可。希望对某人有所帮助,我花了几个星期才找到它。
【解决方案3】:
我现在在 NetCore 2.2 中看到了对这个包的支持:
System.DirectoryServices.AccountManagement
你可以在 nuget 中找到它。
作者是微软和
发布日期:2018 年 5 月 29 日,星期二(2018 年 5 月 29 日)
【解决方案4】:
使用“Microsoft.Windows.Compatibility”,它会编译,但如果您不在 Windows 上运行,则会在运行时获得平台不受支持的异常。
Unhandled Exception: System.PlatformNotSupportedException: System.DirectoryServices is not supported on this platform.
at System.DirectoryServices.DirectoryEntry..ctor(String path)
at ad_test.ActiveDirectoryClient.GetUsername(String emailAddress) in .../ad-test/ActiveDirectoryClient.cs:line 24
at ad_test.Program.Main(String[] args) in .../ad-test/Program.cs:line 11
【解决方案5】:
System.DirectoryServices 有一个预发布版本。您可以使用以下命令从 NuGet 包管理器获取它:
安装包 System.DirectoryServices -Version
4.5.0-preview1-25914-04
到目前为止,这对我来说还不错。