Share an assembly with nuget package – make your assembly accessible from Visual studio Gallery or Local repository

Nuget is a visual studio extension allowing to share libraries (add, remove..).

In this article, First we will create a nuget package to push our assembly in official nuget repository and get it from gallery in visual studio 2010 using NuGet command line. Secondly, we will use a GUI NuGet Package Explorer and create a local repository to share assemblies

In tools menu,click on Extension Manager to install Nuget Package Manager

Download Nuget Package Manager from Gallery. This package will allow to reference

In solution explorer, you can manage Nuget Package by right clicking in reference:

create your nuget account: http://nuget.org/account/Register

and register your API key in order to be authorized to push your nugget package on nuget website:

nuget setApiKey yourapikey

download Nuget.exe from codeplex url: http://nuget.codeplex.com/releases/view/58939

add the Nuget path in environment variables to register nugget application path

run nuget spec yourassembly.dll to create your package

in the assembly folder, you can see a new file with nuspec extension:

when editing the nuspecfile, we can see a xml configuration :

clean this xml file by set your own configuration or delete xml not used:

Create a lib folder and copy the assembly you want to package with nuget. In this lib folder create a framework subfolder (here net40 for framework 4.0) Make a nuget package by this command line:

Nuget pack MyBizservice.dll.nuspec

It creates a nupkg file, your nuget package:

push your package in the nuget server to share it with the command line:

nuget push yourpackage.nupkg

in your Nuget account, go to Package panel and see that your package has been pushed:

from gallery in visual studio , the assembly is now avalaible:

you can also use a GUI to manage your nuget package:

first download Nuget Explorer on codeplex url: http://nuget.codeplex.com/releases/view/59864

after downloading this tool, this dialog box is opened:

Create a new nuget package using the third task

Click on edit menu in order to set the xml configuration for the nuget package:

set the package name and other settings:

finally select the content you want to set in your nuget package by clicking on content menu ,Add and Lib folder (it is the folder where you set assembly for nuget) as follows:

in right panel called package contents, you will see the lib folder you have added

Right click on lib folder to select the target framework (here 4.0) of your assembly (Add .NET folder)

a net40 folder is created:

select this folder and right click to add the assembly you want to package with nuget:

we can see the assembly added in lib folder, save the nuget package by clicking on green save button or CTRL + S:

once saved the package metadata exit from the edit mode:

the package is created on the folder :

for this nuget package we will configure a local repository instead officical nuget repository . First go to options of Toos menu of visual studio:

select Package Manager, and Package Sources :

click on + button to add a new source (here a local repository called MyLocalNugetRepository but it can be a share for a team):

select the folder where you have saved the previous nuget package ( the cursor is hover the explorer button)

we have selected a local folder, click ok: now we have another source for nuget package. Right click in the project in solution explorer on Manage NuGet Packages:

on the left side in the online panel, we see the new NuGet local source we have created and when clicking on it, the previous nuget package appears:

Conclusion:

We have seen how with console create a nuGet package shared in NuGet official package source and how use NuGet explorer to create a nuGet Package and set it in a local repository

Publicités

, , , , , , , ,

  1. Poster un commentaire

Laisser un commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s

Microsoft System Center 2012

All System Center 2012 products, Service Manager, App-Controller, Orchestrator, Virtual Machine Manager, Configuration Manager, Data Protection Manager, Operation Manager -Boutougha Hassan

Microsoft Windows Server 2012

IT - Windows server 2012 - Hassan Boutougha

Microsoft Hyper-V

IT - Hyper-V - Hassan Boutougha

Microsoft SQL Server 2012

IT - SQL Server 2012 - Hassan Boutougha

%d blogueurs aiment cette page :