What is
NuGet?
Read
Learn Nuget Package Manager in 10 Minutes to understand the latest version of Nuget.
According to the NuGet’s official
page,
NuGet is a Visual Studio 2010
extension that makes it easy to add, remove, and update libraries and tools in
Visual Studio projects that use the .NET Framework.
In detail, Nuget is a free, open-source
package management system offered by the Microsoft ASP.Net team to the developer
community to ease the process of integrating any 3rd party open
source component into our project.
There are large numbers of free, open
source re-usable components available around the web which can be re-used in our
projects. For example jQuery, log4net, ELMAH, NInject, Structure Map are few to
note. If you notice, every time when we want to integrate these components into
our project we will spend some considerable amount of time in downloading it,
integrating it and configuring it. Since this is a repeatable task with a scope
for automating it, Microsoft introduced a new add-on for Visual Studio called
NuGet which can find all the available OSS(Open-Source System) components and
integrate it in into our project with their dependent components. NuGet also
takes care updating the config file if the component requires adding some
settings in project config file. It also provides option to update the component
and remove the component if required.
Once installed, this add-in gives both
GUI based and PowerShell based consoles to find and add components into our
project solution. NuGet once loaded will load all the available components
(Packages in NuGet terms) from a centralised feed location and will give an
option to download and integrate it in our projects. For every component, a
package is created and is added with centralised feed system which is then
consumed by the NuGet to fetch the available components. With NuGet, you can
also create a package of your component and add it to the centralised feed for
others to consume thro’ NuGet.
Installing NuGet
You can install the NuGet from the
official page at codeplex. The current version is 1.1 as of
this writing. Currently, Nuget supports visual studio 2010(also developer
edition) in the below platforms.
1. Windows 7
2. Windows Vista SP1
3. Windows Server 2008
4. Windows Server 2008 R2
5. Windows Server 2003 SP2
6. Windows XP SP3
You can install the Nuget through the
Extension Manager in Visual Studio 2010. Next section will guide you to do
that.
Steps
1. Open Visual Studio 2010.
2. Go to Tools> Extension Manager.
3. Extension Manager dialog will load all installed extensions installed
in Visual Studio 2010. See the below figure. If the NuGet is already installed,
it will be listed here.
4. Click “Online Gallery” tab in the above console. This will load all
the available extensions for the visual studio. Once loaded, you can find the
“Nuget Package Manager” add-in. Click Download button to download and install.
Alternatively, you can type Nuget in the search textbox to load only Nuget from
Online Gallery.
5. After downloading, the setup will begin automatically. Refer below.
Click Install.
6. Click Close once you get the below screen.
In next section, we will see how to use
NuGet to find and integrate some 3rd party library using the GUI and
PowerShell commands.
Adding Libraries Using NuGet
GUI
On successful installation of NuGet,
you can see the NuGet option in Tools> Library Package Manager. See the image
below.
Select “Add Library Package
Reference..”. This will bring the NuGet GUI as below. The Installed Packages tab
will show if there are any library(or Package) already added through NuGet in
your project.
Note
I have installed log4net already in the
project; hence you can see it in Installed Packages tab.
To add a new package, select Online
tab. This will load all the available packages in the central feed. You can
select a library and click Install to install the package into the project.
Alternatively, you can search a
particular package in search textbox in to right corner. For example, type
NHibernate in search textbox and click enter. It will display the package with
install option. Refer below,
On clicking install, it will install
the package like below.
Once the selected package is
installed, you can see the selected package’s dll into bin(or in References in
solution explorer), dependant assemblies if any and configuration settings in
config file if any.
Alternatively, you can also use
PowerShell commands to find and add assemblies like above. Next section will
help you to do the same.
|