98

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?

Eilon
  • 25,582
  • 3
  • 84
  • 102
mkaj
  • 3,421
  • 1
  • 31
  • 23
  • Is there an estimate for when they think it's possible to add an existing project of type good old Class Library? This is the last think I exspected to hault my MVC 5 to ASP.NET 5 MVC 6 migration. – radbyx Feb 26 '16 at 06:45
  • "ASP.NET 5 Class Library" has different framework than ASP .NET Core, but core has it own **Core Class Library**, use that instead. – Jaider Feb 07 '17 at 14:41

3 Answers3

100

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

Eilon
  • 25,582
  • 3
  • 84
  • 102
  • can you expand on #2 - do you mean the intellisense suggests an API and then downloads the nuget package for you? I type JQuery and it'll give it to me? – Simon_Weaver Mar 30 '15 at 23:39
  • 3
    @Simon_Weaver I mean that whereas the regular Class Library project produces just a DLL and PDB, the new one generates a NUPKG (NuGet package) that can be uploaded to nuget.org. – Eilon Mar 31 '15 at 03:51
  • 2
    .kproj since then has been renamed to .xproj – Boris Lipschitz Dec 30 '15 at 06:28
10

This is an interesting observation, the current template will generate a class library compatible with ASP.NET 5 runtime. You don't get that from the normal C# class library.

I filed the following issue for tracking this design question - https://github.com/aspnet/Home/issues/281

Yishai Galatzer
  • 8,791
  • 2
  • 32
  • 41
  • I'll watch your issue thanks. Same naming issue with "ASP.NET 5 Console Application" obviously. Maybe should be called "vNext Console Application", otherwise devs may confuse it with some sort of console app to an ASP.NET website. Maybe the location of the templates should be moved from "Visual C# --> Web" to "Visual C# --> vNext" – mkaj Jan 19 '15 at 23:47
  • The github issue has been closed. Better project names - thanks: https://github.com/aspnet/Home/issues/281 – mkaj Jan 20 '15 at 01:07
3

From what I understand one benefit is that the end product of ASP.NET 5 Class Library project is a NuGet package (rather than just the .dll assembly).

You can generate the NuGet package by right clicking the project in Visual Studio 2015 and choosing the "Publish..." option. Or you can use "KPM pack" at the command line.

Also, you have the ability to use the ASP.NET 5 Core runtime so that your library can run cross-platform .

  • Is it badly named? Has nothing to do with ASP.NET? – mkaj Jan 19 '15 at 23:23
  • 1
    One of the key goals of ASP.NET 5 is to allow it to run cross platform. Some have asked "shouldn't this be called .NET Core instead?" At least for now Microsoft's multi-platform approach is only about the web (and console apps) and doesn't support desktop development like Java. To emphasise it's about the web they're branding it all under the name "ASP.NET 5". If you're wanting to produce a library that runs cross platform it should be an ASP.NET 5 Class Library. – Thomas Kadlec Jan 19 '15 at 23:39
  • It means I can tell my boss 'yes' when he asks 'is ASP.NET the best technology' - that's why – Simon_Weaver Mar 30 '15 at 23:41