我创建了一个.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相同的方式添加System.DirectoryServices.AccountManagement,如下所示:
<PackageReference Include="System.DirectoryServices" Version="4.0.0" />
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="4.0.0" />
然而,当我尝试重新加载项目时,我收到以下错误:
该错误意味着.net 4.6框架不包含AccountManagement包,但它应该可用于任何4.0以上。
我是asp .net核心开发的新手,所以我认为我遗漏了一些微不足道的东西,所以对这个问题的任何解释都会很棒。
非常感谢
答案 0 :(得分:0)
您的项目文件需要如下所示
<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>
最后一个是普通参考,而不是包参考。