can't find IWebHostEnvironment in Microsoft.AspNetCore.Hosting.Abstractions assembly in a .NET Core class library

Viewed 12368

I can't reference the IWebHostEnvironment element in my .NET Core class library. I have added NuGet packages Microsoft.AspNetCore.Hosting.Abstractions and Microsoft.Extensions.DepedencyInjection.Abstractions, but it still can't find the type. In the documentation, IWebHostEnvironment is in the Microsoft.AspNetCore.Hosting.Abstractions assembly, but I can't seem to reference the correct assembly.

Is there any other assembly I need to reference?

Project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RootNamespace>LundbeckConsulting.Components.Core</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.6" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.6" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\LC.Components\LC.Components.csproj" />
  </ItemGroup>

</Project>
2 Answers

Please add this to your project file:

<ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

You shouldn't need to specify any other packages for framework. Please follow this link

Pay attention to FrameworkReference attribute.

Related