The following code in my project gets the following error.
public static IServiceCollection AddInfrastructure(this IServiceCollection services,
IConfiguration configuration,
Microsoft.AspNetCore.Hosting.IWebHostEnvironment environment) // Error
{
// .....
return services;
}
Error CS0234 The type or namespace name 'IWebHostEnvironment' does not exist in the namespace 'Microsoft.AspNetCore.Hosting' (are you missing an assembly reference?)
I already import the nuget package.
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />
</ItemGroup>
If you want to use Microsoft.AspNetCore.Hosting.IWebHostEnvironment
in a separate library project other than your web project, you have to explicitly add the Microsoft.AspNetCore.App
package reference to the library project by editing the project file.
In Dotnet 5.0 also, we have to follow same approach.
<Project SDK="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>...</ItemGroup>
</Project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With