1

I am using .Net 5 class library project and here are my refrences. I am using

using Microsoft.AspNetCore.Hosting; But I cannot find IWebHostEnvironment. What wrong am I doing ?

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

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
    <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
    <PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.12.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="5.0.0" />
    <PackageReference Include="Microsoft.Graph" Version="3.19.0" />
    <PackageReference Include="Microsoft.Graph.Core" Version="1.22.0" />
    <PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="5.2.8" />
    <PackageReference Include="Microsoft.ReportViewer.WebForms" Version="10.0.40219.1" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
    <PackageReference Include="System.Runtime" Version="4.3.1" />
    <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.8.1" />
    <PackageReference Include="System.ServiceModel.Primitives" Version="4.8.1" />
    <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
  </ItemGroup>


  <ItemGroup>
    <Reference Include="System.ServiceModel" />
  </ItemGroup>

  <ItemGroup>
    <WCFMetadata Include="Connected Services" />
  </ItemGroup>

</Project>
TylerH
  • 20,799
  • 66
  • 75
  • 101
user1005310
  • 737
  • 2
  • 12
  • 40

2 Answers2

4

On .Net5.0, IWebHostEnvironment has been replaced by IHostEnvironment

Make sure you have the package Microsoft.Extensions.Hosting installed and the following import on the top of the file.

using Microsoft.Extensions.Hosting;

More information can be seen at aspnetcore github discussion

Cafn
  • 137
  • 1
  • 8
  • 26
0

IWebHostEnvironment is included in the Microsoft.AspNetCore.Hosting package, you simply need to add it as a reference to your project by right clicking on your project file and selecting 'Manage Nuget Packages' then searching for Microsoft.AspNetCore.Hosting and add it.

If you've already added it and it still isn't working, try cleaning your project.

whendon
  • 169
  • 1
  • 12