What is NuGet and how do I use it?
Most of you must have gone through the agony that you sometimes feel when adding libraries or tools or managing resource dependencies to use in your project manually, whether it’s a single DLL file to reference, or a pack of files to reference along with taking care of the versions and also updating your config files for them. Most of these issues come when you are trying to work in an already built system and trying to compile and run it to get it to work before you make any changes. Argh!!!! I was victim of these situations a number of times and really hated this time wasting process. But thanks to a great tool that I am about to explain, this process is so much easier and now it’s like 1…2…3 and BAM!!! There you go sir or madam.
Most of you may already be familiar with this tool and must be wondering why I am demonstrating such a basic tool. Well the reason is that this tool now helps us in almost all of our development projects. It’s important to explain this first so that in the following topics, the use of this tool will be known to all. So without further ado, I give you NuGet!
What is NuGet?
NuGet is an open source free package manager for Microsoft .NET Framework. It was formerly known as NuPack, but the name was changed due to confusion with another software with the same name. The NuGet client tools provide the ability to produce and consume packages in development in .NET Framework. It’s a Visual Studio extension that lets us easily manage libraries and tools in a Visual Studio development environment.
How does it work?
When you add a library or tool, NuGet copies files to your solution and automatically makes whatever changes are needed in your project, such as adding references and changing your app.config or web.config file. When you remove a library, NuGet removes files and reverses whatever changes it made in your project so that no clutter is left.
Everything you need to install a library or a tool is bundled into a package (a .nupkg file). A package includes files to copy to your solution/project, a manifest file that describes the contents of the package and instructions on what goes where and what needs to be done to the solution/project to add or remove the library. Packages are bundled into feeds that Visual Studio accesses in order to present lists of available packages. There is an official feed that is the default source for NuGet, and you can contribute to that feed or create your own feeds.
How do you use it?
You work with packages by using a dialog box in Visual Studio or by using PowerShell cmdlets in a dedicated Visual Studio window. Both options are accessible from the Visual Studio main menu; you can also open the dialog box from a Solution Explorer context menu. I will show how to use both ways in a while. The PowerShell cmdlets require PowerShell 2.0. Therefore, NuGet requires one of the following operating systems:
(**Note that NuGet can be used on Visual Studios 2010 or above only.)
Now let me demonstrate how you can use this tool to help you easily manage libraries and tools in your projects/solutions.
Well the first step is to get this baby installed. You can check first to see if your Visual Studios already has NuGet installed. Go to the Tools menu and look for the Library Package Manager. If you don’t find it, then to install NuGet you can use the Visual Studios Extension Manager like demonstrated below.
Go to Tools -> Extensions and Updates.
After clicking on the Extensions and Updates link, a popup window will open showing you all currently installed extensions on your Visual Studios. Using the top right search box, type in “nuget” and hit enter and the NuGet package will show up. As you can see my NuGet is already installed, but if you don’t have it installed on your Visual Studios you will be given the option to do so.
Right! Now that we have NuGet extension installed. Let us now use it in an actual development environment. There are 2 ways of using NuGet, as mentioned before. One is using the graphical dialog box in Visual Studio and the second is by using PowerShell cmdlets in a dedicated Visual Studio window. Let me first demonstrate it using the graphical dialog box that is a lot like the Extensions and Updates dialog box way of installing NuGet.
Pages: 1 2