如何将库项目中的ASP.NET Core 3.0类型用于共享控制器,中间件等? [英] How do I use ASP.NET Core 3.0 types from a library project for shared Controllers, Middleware etc?

查看:143
本文介绍了如何将库项目中的ASP.NET Core 3.0类型用于共享控制器,中间件等?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然可以通过NuGet消耗高达2.2的ASP.NET Core来创建共享控制器,中间件等的库项目,但是我如何创建一个能够使用ASP.NET Core 3.0类型的库?

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 ASP.NET Core 3.0 types?

对于包含视图的项目,有一个剃刀类库(Razor Class Library)( razorclasslib )模板,如何创建仅包含以下内容的库

While for projects containing views there is a "Razor Class Library" (razorclasslib) template, how do I create a library that only contains logic components?

推荐答案

为.NET Core 3.0构建的应用程序可以引用一个或多个共享框架。 ASP.NET Core是这些共享框架之一(其他将是基本的.NET Core共享框架和包含WinForms和WPF的Windows桌面共享框架)。

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).

来自经典.NET Core库的ASP.NET Core,它针对.NET Core 3.0( netcoreapp3.0 ,而不是.NET Standard),则可以使用 csproj中的FrameworkReference 引用框架:

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>

在Visual Studio中打开时,此附加框架引用将显示在解决方案资源管理器的依赖项节点中:

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

这篇关于如何将库项目中的ASP.NET Core 3.0类型用于共享控制器,中间件等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆