C# ASP.NET Core 2.2 GroupPrincipal.FindByIdentity不再存在

C# ASP.NET Core 2.2 GroupPrincipal.FindByIdentity不再存在,c#,.net-core,active-directory,C#,.net Core,Active Directory,我正在尝试将用户添加到AD中的组中,但是下面的示例代码不再有效: UserPrincipal insUserPrincipal = (UserPrincipal)lbUsers.SelectedItem; GroupPrincipal groupPrincipal = GroupPrincipal.FindByIdentity(insPrincipalContext, group.GroupName); if (groupPrincipal.Members.Contains(insPrin

我正在尝试将用户添加到AD中的组中,但是下面的示例代码不再有效:

UserPrincipal insUserPrincipal = (UserPrincipal)lbUsers.SelectedItem;
GroupPrincipal groupPrincipal = 
  GroupPrincipal.FindByIdentity(insPrincipalContext, group.GroupName);
if (groupPrincipal.Members.Contains(insPrincipalContext, 
    IdentityType.SamAccountName, insUserPrincipal.SamAccountName))
{
    MessageBox.Show(insUserPrincipal.Name + 
      " is already a member of group " + group.GroupName);
    return;
}
groupPrincipal.Members.Add(insUserPrincipal);
groupPrincipal.Save();
有人知道如何在asp.net core 2.2中做到这一点吗?我找不到新版本

GroupPrincipal.FindByIdentity(insPrincipalContext, group.GroupName); //No longer exists

编辑:我可以使用GroupPrincipal搜索组等-但是缺少FindByIdentity方法

为了在.NET Core上使用,您需要安装提供此功能的。完成后,您应该能够再次访问
GroupPrincipal
类型。

Hi,我可以访问GroupPrincipal类型-但是似乎不再有一个名为FindByIdentity的方法了?@Hawke有,您确定正在查看正确的
GroupPrincipal
类型吗?你包括那个包裹了吗?您使用的是什么目标框架,.NET Core?我使用的是包System.DirectoryServices.AccountManagement和Core 2.2。Visual studio抛出一个错误,表示“类型名称”FindByIdentity“在类型“GroupPrincipal”中不存在。Nevernind-它现在可以工作了(甚至看不到区别..)