Friday, 7 June 2013

Using NuGet PowerShell to reference a lower version of a package in Visual Studio

(This article assumes you have installed NuGet on Visual Studio via Tools -> Extensions and Updates)

NuGet is a great tool to reference a package without requiring the user to download one in their local machine, and its repository lets you reference the latest version of a particular package with only a few mouse clicks. However, you may want a lower version of the package because of compatibility issues (for example, Microsoft EnterpriseLibrary v6.0 is not compatible with .Net 3.5). 
 This can be done via NuGet's PowerShell (command prompt) quite conveniently. 


Firstly, check the ID of the package you want;
    Right-click on Reference for the project -> Manage NuGet Package -> Online (panel on the right)
and search for the package name. 




Clicking on the package will display details on the right-hand side panel, and Id is what you want to note down.



Now, Go to Tools -> Library Package Manager -> Package Manager Console



It will open a command-line prompt at the bottom of the screen. Type in;
Get-Package -ListAvailable -AllVersions PACKAGE_ID
You will see a list of versions for the package.




Make sure "Default project" selected on the command prompt is the project you want to install reference.
Then type in;
Install-Package Newtonsoft.Json -Version 5.0.5
Where Newtonsoft.Json should be substituted by your package id, and 5.0.5 with your desired version.

The reference has been made, so you can now use the package in your code. 




No comments:

Post a Comment