Search code examples
asp.net-core.net-coreclass-library

Unable to add Microsoft.AspNetCore package to the class library project


I have an ASP.NET Core 7 project which has a reference from a shared class library project. In my shared class library, I have a method which access a webApplication object as argument.

The problem is that this class is part of the Microsoft.AspNetCore package and I could not find this package in nuget package manager to add my shared class library project.

Can anybody help me how to solve this problem?

Thanks in advance


Solution

  • I searched and found this section which metioned

    To reference ASP.NET Core, add the following element to your project file:

    <Project Sdk="Microsoft.NET.Sdk">
    
      <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
      </PropertyGroup>
    
      <ItemGroup>
        <FrameworkReference Include="Microsoft.AspNetCore.App" />
      </ItemGroup>
    
    </Project>
    

    And I create a Class Library and test it.

    enter image description here enter image description here