Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
143 views
in Technique[技术] by (71.8m points)

c# - Why create an ASP.NET 5 Class Library project?

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?

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.

Why does the name have "ASP.NET" in it?

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 Console Application (Cross-platform)
  • .NET Class Library (Cross-platform)

Update 5/13/2015

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

  • Class Library (Package)
  • Console Application (Package)

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

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.

VS2015 RC Class Lib / Console App templates


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...