我创建了一个.net核心应用程序,我以完整的.net 4.6框架为目标,以便使用System.DirectoryServices连接到Active Directory。我已经更改了csproj文件,如下所示,将net46添加到目标框架并添加system.directoryservices。
<PropertyGroup>
<!--<TargetFramework>netcoreapp1.1</TargetFramework>-->
<TargetFramework>net46</TargetFramework>
<PackageTargetFallback>portable-net45+win8</PackageTargetFallback>
<UserSecretsId>fdd24e9b-cd56-499e-9c1b-f8ef2b24ba09</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.0" />
<PackageReference Include="System.DirectoryServices" Version="4.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
</ItemGroup>
这一切都按预期工作,我可以重新加载项目,并完全使用目录服务。我现在尝试添加System.DirectoryServices.AccountManagement,其方式与添加System.DirectoryServices相同,如下所示:
<PackageReference Include="System.DirectoryServices" Version="4.0.0" />
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="4.0.0" />
然而,当我尝试重新加载项目时,出现以下错误:
无法解决错误
该错误向我暗示 .net 4.6 框架不包含帐户管理包,但它应该在 4.0 以上的任何版本中可用。
我是asp .net core开发的新手,所以我假设我错过了一些微不足道的东西,所以对这个问题的任何解释都会很棒。
非常感谢
您的项目文件需要如下所示,
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net46</TargetFramework>
<RuntimeIdentifier>win7-x86</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.DirectoryServices.AccountManagement" />
</ItemGroup>
</Project>
最后一个是普通引用,而不是包引用。