NuGet creation

NuGet creation
The last time I spoke as NuGet is used, this time it is logical to tell you how to create your NuGet package and place it on a shared hosting or on your own in a local directory, or else in the gallery.

Creating your own package NuGet

For example, and I think in most cases, you’ll create a package NuGet without dependencies on other packages. So we need any project, for simplicity let it be a simple library with the N- of methods.

In order to be able to set library or libraries to include in the final NuGet package, you must add the project file with the extension “.Nuspec“, where there will be described all the properties and the internal function of our package. So far, in the studio there is no setting to create the files required extensions, so that you can create any text file, and change it’s dwells.

In general, the nuspec file looks as follows:

<?xml version="1.0" encoding="utf-8"?>
<package>
  <metadata>
    <id>WBR.ArgParser</id>
    <version>1.0.0</version>
    <title>Argument Parser library</title>
    <authors>Violet Tape</authors>
    <description>Easy to use library for parsing app arguments.</description>
    <language>en-US</language>
    <projectUrl>http://violet-tape.net</projectUrl>
    <iconUrl>http://violet-tape.net/images/commandprompt.png</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
  </metadata>
  <files>
    <file src="bin\Release\WBR.ArgParser.dll" target="lib" />
  </files>
</package>

 

We can say that the comments here are irrelevant. The only thing that is necessary to specify is which tags are mandatory and which are optional.

Mandatory tags:

  • id – can not specify a name with spaces or special characters. In general, here are the same rules that apply to URL
  • version – package version in the format 1.2.3.
  • authors – list of the authors of code separated by commas
  • description – the description of what makes the package

Everything else is optional and is filled on their own. There is no particular limitation, but iconUrl – recommend 100×100 image in png format with transparent background. Such are the demands.

If you want to invest in the package a lot of files and to prescribe them by hand , as any normal programmer is too lazy, you can use a batch addition of the mask. Examples of adding and using below.

<files>
  <file src="c:\docs\bin\*.xml" target="lib" />
  <file src="bin\Debug\*.dll" target="lib" />
  <file src="bin\Debug\*.pdb" target="lib" />
  <file src="tools\**\*.*" />
</files>

 

After nuspec file will be created, we need NuGet.exe to pack everything into the final file nupkg. This operation is doing with the help of the command

Pack “Path.To.Nuspec.File”

It is best to put the command into PostBuild action in successful assembly and from there to pick up ready-made package

“$(SolutionDir)Tools\NuGet.exe” pack “$(SolutionDir)ArgParser\ArgParser.nuspec”

After performing such uncomplicated actions you will completely ready and the work package, which may be placed on the official hosting or on your own.

The easiest way to start posting packages from local or network folders. This is the simplest and easiest way, which does not require any significant effort on your part.

Packages in the local directory

Let’s say you have chosen as a repository package local directory C: \ NuGet. Want to copy back all the packages you want, and then configure the package manager NuGet in this directory. This is done as follows:

Call Manager Package Tools > Library Package Manager > Package Manager Settings

After that the window will appear with the settings, where you can specify the package repository.

Enter the name of the repository and the path to the folder with the packages, then click Add and you can try to add packages NuGet from a new repository.


As you can see in the picture, there’s a new resource LocalRepository when allocation of it it, downloads the NuGet , which were placed in the appropriate folder. Similarly, all will work with network folder.

As you can see, everything is more than easy!

Placing in the gallery

Place in the general gallery of packages NuGet possible after registering on the site http://nuget.org/. Registration process is very simple, and here consider it does not make sense. After the registeration, you can add your package.

Adding is possible in two ways: through a Web interface and command-line using NuGet.exe.

Adding through the web interface

Click on the GetStarted and follow the instructions.

After the package is loaded, you will be redirected to a page where you can edit the data that was listed in nuspec file.

After you are satisfied that everything is filled properly, you can press on Next at the bottom of the page and you’ll be taken to setup a logo or a screenshot of the package. This will be the final step in the publication.

After clicking Finish, about a minute you can go to the tab My Contributions and see your packadge.

In passing to the page you can edit the package some of its properties, delete it. Learn how many people have downloaded the package, find out what other people think about your product.

Adding through the command line

After registering, you can find your GUID to update and add packages using the command line utility nuget.exe. Know your GUID may be in the tab MY ACCOUNT, in the upper right corner. After clicking on the specified menu item, you will see the following picture

nuget push -source http://packages.nuget.org/v1/ MyPackage.1.0.nupkg 64f10e0c-207a-4728-95bb-1b0e0f469511

GUID is fake, so that everything is O.K)) But you shouldn’t tell anybody your own. On this page as you can see an example , as deploit your packages from the command line

Push is the first parameter which says that we download the package, followed by the parameter source, who says, where we load the package. Next comes the name of the package to download, and most recently held a secret option GUID.

In generalthere is nothing particularly complicated.

Placement on personal hosting

This method is ideal accommodation if you have a proprietary libraries or commercial software , and a project is big and the work is done by several teams. In the future community plans to make such a placement package easier and more functional.

At the moment the private gallery package only supports return packages, download them we will do by hands.

To create a distribution package of the site will need to first create a blank project Web site.

After creating the project type the command in Package Manager: install-package nuget.Server

After that, downloading and instalingl all the packages dependencies. Blank project ready to become a server for the packets. There will be new directory. The most important for us, this folder Packages, in which actually will be adding ready packages NuGet.

Add the existing packages in a folder and you can run the site. After starting ,see the following:

Comments on the site speak for themselves. Now you can add the site to available resources and see how it all works.

After this, open the package manager, select the resource and watch as shown our packages

Voila!

I hope this knowledge will help you in the future and come across to any new uses NuGet, the possibility of decomposition of your projects and upload dependent parts through NuGet.

For myself, I had already decided that, regardless, I will try to connect through NuGet. In this case the libraries loaded locally and do not need to keep track of the correct paths to link to the library. And even the newcomers will not make mistakes, if connect the link on nunit through NuGet, because all team members will receive the correct path to the library and will not be screaming on “The Right to the relative path of the project!”;)

Tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>