Saturday, June 7, 2014

Step By Step How to create a custom NuGet Package

       By Carmel Shvartzman
In this tutorial we'll learn How to create a NuGet Package , containing a template with the Controllers, Views, Images, CSS & Scripts that you need in your Asp.Net MVC applications. We'll save our package in intranet or local file system, and use it every time we create a new project.
For this tutorial, we'll  create an MVC application as Template to future projects, and save it as a NuGet Package.
Then, we'll create an empty MVC application, and we will use that NuGet package as a bootstrap for the new project , showing as follows:




First thing, browse to the Visual Studio Gallery at MSDN & update your NuGet Package Manager:


Next, you'll need a free tool called NuGet Package Explorer , at CodePlex :


Now, build the MVC application template that you want to save. For example, create an empty MVC app & add a View just as:



And also a Controller:


1) EVERY code file MUST be appended " .pp  "
2) in the code, the namespace name MUST be replaced with a generic " $rootnamespace$ " 


Now open the NuGet Explorer that you downloaded , & create a New package:

Edit the package taking care of setting Title, Author, Description, Language, Tags & Summary :


Edit whatever Dependencies the package should have :



Then add a Content folder:


Paste inside it all files & folders from your application, that you want to be part of your template :


Check whether you got all you need for your package:


Then add the DLLs from your template to the package:


First set the Framework version you want:


Copy-paste the DLLs :


Save the Package :


And Analyze it for errors:





Now go to the NEW project where you want to IMPORT the NuGet Package. Open the NuGet Manager at Settings & tell it WHERE to look up for your local Packages:


Finally, open the NuGet Manager:

Find your Package at the FOLDER WHERE you put it:

Take a look where go the Title, Summary etc.
Install your custom NuGet Package :

Check whether you got the whole template:





That's all!! 
In this tutorial we've learn how to create a NuGet Package hosted in the local file system, containing a template with the Controllers, Views, Images, CSS & Scripts that you need in your Asp.Net MVC applications. 

Happy programming.....


כתב: כרמל שוורצמן