Edit: If you are in a hurry (like I am many times) check Nuget Package Explorer which is an excellent tool to create and publish a Nuget Package. If you want to know more about how a Nuget package is created then keep reading…!
In a previous post a mentioned a BBCode helper based on an existing library (BBCode Parser). In this post let’s se how can we create a package using NuGet in order to be used via the package manager inside Visual Studio!
First we choose what files we want to include in our package. For BBCode Package we will include the initial assembly and the helper which is a C# razor file
Then we need to create an xml with the extension .nuspec
The schema for this xml is located at Nuspec Format in Codeplex
Our xml looks like this
<?xml version="1.0" encoding="utf-8"?> <package> <metadata> <id>BBCode</id> <title>BBCode Parser and Helper</title> <version>0.2.0</version> <authors>[BBCode Helper - John Katsiotis], [BBCode - codekicker.de] </authors> <description>BBCodeHelper is a helper based on an excellent BBCode parser available at Codeplex This package contains a helper that can be used with Razor Syntax for easy set up!</description> <projectUrl>http://john.katsiotis.com/blog/bbcode-helper-for-webmatrix-and-asp.net-mvc-razor-view-engine</projectUrl> </metadata> <files> <file src="lib\*.dll" target="lib" /> <file src="content\*.cshtml" target="content\App_Code" /> </files> </package>
and it will be used to generate the package file.
With the above xml we have succeeded in creating a package that will put “a few” dlls in the bin folder and “a few” files inside App_Code folder located at the root of our project. If the folder App_Code does not exists it will be created.
This is because folder lib is being copied at the bin directory of the project and folder content is copied at the root of the project.
Let’s see how the file structure looks like
Now we need to open a command-line (download nuget.exe command-line tool) and execute the following command inside the folder that the above files are located.
nuget pack BBCodePackageManifest.nuspec
If the command is executed successfully we have just create our NuGet Package! Congrats!
Don’t forget that these packages can be very easily used via WebMatrix also.
The article above used the CTP2 bits! Updated!