当 .Net 核心 Web 应用程序以完整的 .Net 框架为目标时,哪个 Class 库用于 ASP.NET 核心标记助手?

Which Class Lib for ASP.NET Core tag helpers when .Net Core Web App targets Full .Net Framework?

我已经创建了一个 Asp.Net 核心 Web 应用程序,它以完整的 .Net 框架为目标。这是通过使用 Visual Studio ASP.NET 核心 Web 应用程序 (.NET Framework) 模板完成的。

我想创建一些我在此 Web 应用程序中使用的标签助手,我想将它们放在库 dll 中。最初我尝试将一个新项目添加到我的 Class 库 (.NET Core) 类型的解决方案中以放置它们,但我无法从 Web 项目中引用该库。当我尝试通过 Visual Studio 引用它时,我收到一个对话框,提示不支持项目引用,因为 Class 库的目标框架与我的网站项目中的目标不兼容。

因此,作为替代方案,我通过 Visual Studio Class 库模板向解决方案添加了一个常规 Class 库 项目。我能够成功地将我的 Web 项目的引用添加到这个 class 库。但是,在这个 Class 库项目中,我找不到引用 Microsoft.AspNetCore.Razor.Runtime 的方法,如果我要能够将我的标签助手放入库中,这是必需的。

所以我对这两种方法都走投无路。我怎样才能将我的 ASP.NET 核心标签助手放在一个 class 库中,我可以从我的 ASP.NET 面向完整 .net 框架的 Web 项目中引用它?

When I tried to reference it via Visual Studio I received a dialog that said the project reference was not supported because the Class Library has a target framework that is incompatible with the targets in my Website Project.

这通常意味着您的两个库都以不同的目标为目标,即如果您的 Class 库以 netstandard1.6 为目标,而您的 Web 应用程序以 net452 为目标,则它无法正常工作。

您的 Web 应用程序需要以 netcoreapp1.0 为目标,或者您的 class 库必须以 netstandard1.0 为目标。使用此处的 .NET Standard Library matrix 查看哪个 netstandard1.x 名字对象支持哪个平台。

因此,如果您的 Web 应用程序以 net452 为目标,则您必须以 netstandard1.0netstandard1.1netstandard1.2 为目标。 netstandard1.3 及更高版本不起作用,因为它需要 .NET Framework 4.6。

如果您使用需要 netstandard1.3 或更高版本的库,则必须针对多个平台。即 net452netstandard1.3

然后 net452 将用于以 net452 为目标的项目, netstandard1.3 将用于 netcoreapp1.0 应用程序或其他以 netstandard 为目标的 class 库.