IWebHostEnvironment not working in one of the class library projects

vkagarwal 1 Reputation point
2021-06-28T19:44:38.26+00:00

Hi,

I am working on a project which is based on .Net Core 3.1. I have couple of class library projects.

Both of the class library projects reference IWebHostEnvironment in the class constructor but one project builds successfully while another fails.

I have Microsoft.AspNetCore.Hosting nuget package referenced in both projects but still one works while other fails. I had to add Microsoft.AspNetCore.App nuget package to make other project build and work.

Why this is happening while both projects are in same solution and both projects are based on .Net Core 3.1

Thanks

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,161 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jerry Cai-MSFT 986 Reputation points
    2021-06-29T08:17:00.493+00:00

    Hi, vkagarwal

    You can add

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

    to your project then solve the problem.

    About the reason, you can check this :

    Framework reference

    Best Regards,
    Jerry Cai


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.