Creating and then using a NuGet local repository
In this blog post I am going to cover the creation and usage of a local NuGet repository.
In this example I am going to add the Microsoft Bits (Background Intelligence Transfer Service) dll to a web application.
1 – First of all I created a folder on my hard drive simply called NuGetPackages. (c:\NuGetPackages)
2 – Fire up VS 2010 and then create a new web application or open an existing one so that we can use this to test the new package were creating.
3 – Once you have the web application open, you’ll want to change where Visual Studio 2010 looks for the packages locally, to do this go to the Tools menu, and select Library Package Manager, from there then select Package Manager Settings (as seen below)
Once selected we need to change where Visual Studio and more specifically where NuGet is looking to try to find our local packages. Type a name and then paste in the location in the source textbox and press Add. You should see something like this:-
4 – Ok at this point we have only created a location to put the packages, and told NuGet where to locate them. Now we need to create a package.
5 – Time to create a package, first of all you need to create a file with the extension .nuspec and this file will be an xml file which will have the following structure:-
Element |
Description |
id | The identifier for the package. It used as a partial name of the package. |
version | The package version. Also used as a partial name of the package. |
authors | Author(s) name. Use a comma to separate multiple authors. |
description | Describe your package for others to understand what the package is used for. |
I created a file called Bits.nuspec and put this into the folder created in step 1) (c:\NuGetPackages) you can see my file below:-
6 – Now we need to build the package and to do this we need to have downloaded the Nuget command line tool which you can get from here:- Nuget command line tool
7 – To make life easier I copied this file (Nuget.exe) to the folder in step 1 (c:\NuGetPackages), now open a command prompt and then change to this directory c:\NuGetPackages, now to create the package just type:-
Nuget.exe pack Bits.nuspec
This should create a file with the extension .nupkg for me this was Bits.2.0.0.0.nupkg as it uses the version information as part of the name. (The version info comes from the .nuspec file)
8 – So far we have created a package and if you look at the last part of the code in Step 5, you’ll see a reference to files, this has *.dll and in this instance will add any dll’s found in this folder to the package. This would not be what you want if your going to be adding lots of different dll’s for other packages, you can change this line to read:-
<file src=”\bin\Release\*.dll” target=”lib” />
Where would be changed to relate to the package you want to add – the line above is just used as an example.
9 – To Install the package we will use the Package Manager Console from within VS 2010 which is installed when you install NuGet firstly you can type List-Package
to see all the packages you have and then type Install-Package Bits
to install the package called Bits.
10 – Now we should be ready to try it out – go back to VS 2010 and then this time select Tools, Library Package manager and then Add Library Package Reference as below:-
Select the package we installed, in this case Bits and click Install as below:-
That’s all there is to it, hope someone out there found this of use.
[…] At the time in which you will read this tutorial, the ACS Extensions NuGet will be available on the NuGet official package source: please select Umbraco.ACSExtensions from there. At the time of writing the ACS Extensions are not published on the official feed yet, hence in the figure here we are selecting it from a local repository. (If you want to host your own feed, see Create and use a NuGet local repository) […]
Hi, Thank you very much for your interesting post.
could you please let me know how I can add my dll’s in my package to a new project as references ?
Open the Solution containing your new project.
Open Package Manager Console.
Select your Package Source and the project you need to add from the drop down list
Install-Package
This tutorial was for creating your own nuget repository locally – not for adding a package to a project.
This is what I was looking for, very useful. Thanks for sharing it.
[…] NuGet (http://gregorsuttie.com/2011/01/03/using-a-nuget-local-repository/) […]
[…] NuGet (http://gregorsuttie.com/2011/01/03/using-a-nuget-local-repository/) […]
use the Nuget Package Explorer to create the package, much easier than typing XML… Drag your items into it and bam publish…
http://npe.codeplex.com/
Yip – this post is quite old and will be blogging about Nuget Package Explorer and more very soon.
It’s really helpful for creating package. Thanks a lot to you. As your documentation, I can create package which may use in earlier version of .Net but I could not use it on .net core app.
[…] NuGet (http://gregorsuttie.com/2011/01/03/using-a-nuget-local-repository/) […]