How do I use ASP.NET Core 3.0 types from a library project for shared Controllers, Middleware etc?

前端 未结 1 2013
有刺的猬
有刺的猬 2020-12-14 15:47

While ASP.NET Core up to 2.2 could be consumed through NuGet to create library projects for shared Controllers, Middleware etc, how do I create a library that is able to use

相关标签:
1条回答
  • 2020-12-14 16:19

    Applications built for .NET Core 3.0 can reference one or more shared frameworks. ASP.NET Core is one of these shared frameworks (others would be the base .NET Core Shared framework and the Windows Desktop Shared Framework containing WinForms and WPF).

    To reference ASP.NET Core from a classic .NET Core library targeting .NET Core 3.0 (netcoreapp3.0, not .NET Standard), you can use a FrameworkReference in the csproj to reference the framework:

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

    When opened in Visual Studio, this additional framework reference will show up in the dependencies node in solution explorer:

    enter image description here

    0 讨论(0)
提交回复
热议问题