为什么要创建 ASP.NET 5 类库项目? [英] Why create an ASP.NET 5 Class Library project?

查看:26
本文介绍了为什么要创建 ASP.NET 5 类库项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚ASP.NET 5 类库"(vNext) C# 项目与 ASP.NET 有什么关系.为什么用这个模板创建一个项目而不是一个普通的 C#类库"项目?

I'm trying to figure out what an "ASP.NET 5 Class Library" (vNext) C# project has to do with ASP.NET. Why create a project with this template rather than just a regular C# "Class Library" project?

我喜欢新功能,例如project.json文件而不是.csproj文件等,但是当项目与ASP.NET无关时创建ASP.NET"类库似乎不太合适或 IIS 等.它只是业务逻辑层的一个项目.一个新的 WebApi ASP.NET 网站最终将引用该项目,但此时这无关紧要.

I like the new features, such as project.json file rather than .csproj file etc, but it doesn't seem right to create an "ASP.NET" class library when the project has nothing to do with ASP.NET or IIS etc. It's just a project for the business logic layer. A new WebApi ASP.NET web site will eventually reference this project, but that's not relevant at this point.

它只是名字不好吗?它应该被称为vNext 类库"而不是使用看起来像网络应用程序的图标吗?

Is it just badly named? Should it just be called "vNext Class Library" and not use an icon that looks like a web app?

推荐答案

为什么要创建 ASP.NET 5 类库项目?

与类库项目 (.csproj) 相比,ASP.NET 5 类库项目 (.kproj) 有许多优点:

Why create an ASP.NET 5 Class Library project?

There are a number of benefits of ASP.NET 5 Class Library projects (.kproj) over Class Library projects (.csproj):

  1. ASP.NET 5 类库轻松支持将项目交叉编译到多个目标,例如 aspnet50aspnetcore50net45 和各种其他可移植类库变体.这包括对 Intellisense 的丰富 Visual Studio 支持,以通知您哪些 API 可用于哪些目标.
  2. NuGet 包是自动创建的,这在类库中非常常见.
  3. 在文件系统更改时自动刷新解决方案资源管理器等方面的工作效率更高.尝试合并 *.csproj 文件中的冲突更改时,源代码管理中的冲突更少.
  4. 可以跨平台编译(部分原因是它不依赖于 MSBuild)
  1. ASP.NET 5 class libraries easily support cross-compiling projects to multiple targets, such as aspnet50, aspnetcore50, net45, and various other portable class library variations. This includes rich Visual Studio support for Intellisense to notify you which APIs are available for which targets.
  2. NuGet packages are automatically created, which is an extremely common thing to do with class libraries.
  3. Better productivity when it comes to things like automatically refreshing Solution Explorer when the file system changes. Fewer conflicts in source control when trying to merge conflicting changes in the *.csproj file.
  4. Can be compiled cross-platform (in part because it doesn't depend on MSBuild)

您可以从 *.kproj 项目中引用 *.csproj 项目(这在 Visual Studio 2015 的新预览版中变得更加容易),但始终可以通过一些手动步骤来实现.

You can reference a *.csproj project from a *.kproj project (this was just made a lot easier with the new preview of Visual Studio 2015), but it was always possible with some manual steps.

就名称而言,这是一个很快就会得到解决的历史遗迹.新项目类型的用途远远超出 ASP.NET 5 应用程序.希望在 Visual Studio 的未来预览中看到新名称:

As far as the names goes, it's a relic of history that will soon be addressed. The new project type is useful far beyond ASP.NET 5 applications. Expect to see new names in a future preview of Visual Studio:

  • .NET 控制台应用程序(跨平台)
  • .NET 类库(跨平台)

随着 Visual Studio 2015 RC 的发布,您可以看到更新的项目模板名称:

With the release of Visual Studio 2015 RC you can see the updated project template names:

  • 类库(包)
  • 控制台应用程序(包)

这些使用 project.json 文件和 .NET 执行环境 (DNX) 来构建、运行和打包(到 NuGet 包中)项目.

These use the project.json file and the .NET Execution Environment (DNX) to build, run, and package (into a NuGet package) the project.

这些项目模板继续显示在Web"节点下的新建项目"对话框中,但现在也显示在Visual C#"主节点中.

These project templates continue to show up in the New Project dialog under the "Web" node, but now also show up in the main "Visual C#" node as well.

这篇关于为什么要创建 ASP.NET 5 类库项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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