c# - 使用将 net461 设置为唯一框架的 ASP.NET Core Web 应用程序 (.NET Core) 与使用 (.NET Framework) 模板之间的区别

标签 c# asp.net .net asp.net-core

随着 .NET Core RC2 的发布,微软推出了 3 个 Web 应用程序模板:

  • ASP.NET Web 应用程序(.NET Framework)——旧的
  • ASP.NET Core Web 应用程序(.NET Framework)——新的,仅在 Windows 上托管
  • ASP.NET Core Web 应用程序 (.NET Core) — Linux、OSX、Windows

我正在尝试使用新的核心 Web 应用程序模板,但没有尝试以 Linux、OSX、Windows 为目标,因此 ASP.NET Core Web 应用程序(.NET 框架)似乎非常适合我。我花了一段时间,但我了解到,为了添加一个适用于此项目类型的类库,您需要添加一个类库 (.NET Core) 并将框架部分更改为仅 net461 以匹配 Web 应用程序。

"frameworks": {
    "net461": { }
}

我的问题:

创建 ASP.NET Core Web 应用程序 (.NET Core) 和在 project.json 中使 net461 成为唯一目标框架有什么区别

只需创建一个默认仅包含 net461 的 ASP.NET Core Web 应用程序(.NET Framework)项目。

是否还有其他我不知道的差异,例如项目的发布方式等?

最佳答案

What is the difference between creating a ASP.NET Core Web Application (.NET Core) and in project.json making.NET461 the only target Framework

这与制作ASP.NET Core Web Application (.NET Framework) 项目是一样的。两者之间的项目类型由 .csproj 文件确定,您在 .csproj 中将其从目标 .NET Core 更改为目标.NET 框架。在 ASP.NET Core 的先前版本/测试版中,可以将两个框架都放在一个 project.json 文件中(已被简化的 . .NET Core 2.0 中的 csproj 文件,更多 .NET 开发人员熟悉)但您只能发布到一个。

just creating a ASP.NET Core Web Application (.NET Framework) project which only includes.NET461 by default.

Are there other difference that I am not aware of like the way the the projects are published, etc If you target the .NET Framework and not .NET Core your app cannot be cross platform and your app can only run on Windows and not Linux/Mac.

ASP.NET Core Web 应用程序 (.NET Core) 和 ASP.NET Core Web 应用程序 (.NET Framework) 是因为后者允许您使用依赖于 Windows 的函数、包或第三方库,并且需要相同的 .NET Framework 或更高版本安装在机器上。

前者没有 .NET Framework 要求,但允许您的应用程序是跨平台的,当您发布应用程序时,它会发布所有相关的 .NET Core dll 文件以这种方式绕过 .NET Framework 安装要求发布到发布目录。

它还会影响编译,就好像您以 .NET Core 为目标并使用 Windows 特定函数或包一样,您将遇到编译错误。

您可以通过调整您的 .csproj 来轻松地在两者之间切换以定位一个或另一个。

Microsoft Docs

You should use .NET Core for your server application when:

  • You have cross-platform needs.

  • You are targeting microservices.

  • You are using Docker containers.

  • You need high performance and scalable systems.

  • You need side by side of .NET versions by application.

You should use .NET Framework for your server application when:

  • Your application currently uses .NET Framework (recommendation is to extend instead of migrating)
  • You need to use third-party .NET libraries or NuGet packages not available for .NET Core.
  • You need to use .NET technologies that are not available for .NET Core.
  • You need to use a platform that doesn’t support .NET Core.

更新(2018/10/30)

已经announced ASP.Net Core 3 的发布日期为 2019 Q1 , 将仅支持 .NET Core .NET Framework

As announced on the .NET Blog earlier this month, .NET Framework will get fewer of the newer platform and language features that come to .NET Core moving forward, due to the in-place update nature of .NET Framework and the desire to limit changes there that might break existing applications. To ensure ASP.NET Core can fully leverage the improvements coming to .NET Core moving forward, ASP.NET Core will only run on .NET Core starting from 3.0. Moving forward, you can simply think of ASP.NET Core as being part of .NET Core.

Customers utilizing ASP.NET Core on .NET Framework today can continue to do so in a fully supported fashion using the 2.1 LTS release. Support and servicing for 2.1 will continue until at least August 21, 2021 (3 years after its declaration as an LTS release) in accordance with the .NET Support Policy.

关于c# - 使用将 net461 设置为唯一框架的 ASP.NET Core Web 应用程序 (.NET Core) 与使用 (.NET Framework) 模板之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37452041/

相关文章:

c# - 有效地加入内存列表

c# - web.config 中的 customError 仅适用于 .aspx 页面

c# - SQL Server 添加字符串值时列名无效

.net - 从 List<Task> 中删除已完成的任务

.net - IfxConnection 和线程可以相处吗?

c# - 为什么 C# 编译器不抛出 null 的逻辑比较?

c# - 避免角色因胶囊对撞机而跳跃

c# - .NET WebClient - 上传数据并获取流

asp.net - 如何在我的 web.config 中设置默认的 text/html 内容类型?

c# - 输出一个 ISO 8601 字符串