If you are following the progress of ASP.NET Core 1.0, then you must have realized the list of new features of ASP.NET Core 1.0 is quite long. I tried to cover some of them in my earlier posts here and here. And one of the new feature was introduction of a new Class library (Package) project template. This new project template allows you to create Nuget package of your class library, instead of DLL.
Before we jump to this new project template, let’s briefly understand the types of class library projects.
Class Library project is a great way to share your code in form of DLLs. Class library project when compiled, produces dll which you can share. Having said that, class libraries aren’t a “one size fits all” solution. As, when you wish to target multiple platforms then you have to compile your code multiple times against target multiple platforms. So you end up having many class libraries targeting the specific platforms, with same functionality or logics.
Class Library (Portable)
Class library (Portable) was created to solve the issue of multiple platform support with class library. PCL can produce a binary that can be referenced by a set of platforms. So when you create a PCL project, you will be asked about targeted platforms.
And the PCL will run only on selected frameworks without creating duplicate copies of for various platforms. But if tomorrow a new platform comes then created PCL is not compatible with it. It needs to be re-published a new version of the library, adding the new platform in the target list.
Class Library (Package)
To address the problem with PCL, microsoft introduced .NET Platform Standards. The idea here is to build your libraries for target platform standards instead of target platforms. To know more about .NET Platform Standards, please read my post DotNet 5.4 or .NET Platform Standards.
Class Library (Package) is a class library project that is configured to allow you to build reference libraries that compile directly into NuGet packages. Nuget Packages have advantage over dlls like when Nuget package is referenced, then it will automatically download and install all the dependencies and also does the conflict management. And the advantage of Class Library (Package) is that it is backward compatible, future compatible and can target multiple platforms.
Enough talk. Now let’s see Class Library (Package) in action.
Create a Nuget Package from Class library Package
First make sure that you have installed ASP.NET and Web Tools 2015 (RC1 Update 1) update to VS2015.
Now open Visual Studio 2015, and create new project. And from project template dialog box, select Class Library (Package).
Note that the name of the library is your Nuget Package ID and it’s not editable afterwards. So make sure you get it right.
Now let’s leave everything as it is and build the application. After successful build, go to bin folder. And you will be surprised to see that nothing is generated. Well, that is because ASP.NET core 1.0 projects are built in-memory by the runtime and no artifacts are persisted to disk. Well, this can be changed easily. Right-click on the project and select the Properties menu item. In the Build tab check “Produce outputs on build”. And now build the project.
Once successfully build, now revisit bin folder.
That’s all folks. Keep visiting this blog and share this in your network. Please put your thoughts and feedback in comments section.PS: If you found this content valuable and want to return the favour, then