Milad Ahmadi
Milad Ahmadi

Reputation: 778

How to access IWebHostEnvironment in class library .NET 5?

I'm using ASP.NET Core 5
I want to access IWebHostEnvironment in classlib but when I try to install Microsoft.AspNetCore.App in nuget I get this warning:
A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting .NET Core 3.0 or higher how do I do to access IWebHostEnvironment in .NET 5 classlib ?

Upvotes: 12

Views: 5284

Answers (1)

Zhi Lv
Zhi Lv

Reputation: 21656

Double click the Classlibrary project to open the <ClassLibraryName>.csproj file, then, add the following code:

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

Then, you can use IWebHostEnvironment in the Classlibrary, the result as below:

enter image description here

Upvotes: 24

Related Questions