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

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> 
Add Comment
2 Answer(s)

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

Add Comment

If you look at the documentation for that interface, you’ll see it’s introduced with version 3.0.

You are referencing version 2.2.0.

Answered on July 16, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.