Tag Archives: nuget

Migrating Away from Nuget.exe

David Ebbo wrote a great blog post way back in 2014 about migrating away from using Nuget.exe in your solutions (it was the old way of doing it). Every now and again, I come across an old project which requires such a migration. The Nuget documentation used to have a page which explained how to do that, but they seem to have removed it. So, I will outline the steps here.

So, to recap, remember when we used to have the Nuget.exe as part of the solution?

Figure 1 – exe in the solution

We need to remove this and move to the modern way of implementing Nuget package restore.

  1. Delete the hidden .nuget directory. Nuke it from orbit (it’s the only way to be sure!).
  2. Open all your .proj files in a text editor and remove references to nuget.targets.

With Step 2, you will be looking for something like the following:

<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />

And possibly also:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />

Be gone with that stuff.

In the solution file, it will look like this:

Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{E6774590-A85E-47D2-8603-10EAAE39A240}"
	ProjectSection(SolutionItems) = preProject
		.nuget\NuGet.Config = .nuget\NuGet.Config
		.nuget\NuGet.exe = .nuget\NuGet.exe
		.nuget\NuGet.targets = .nuget\NuGet.targets

And now you are done. So long as Visual Studio is configured to update packages automatically, you are good to go.

Find Packages on Nuget Using the Package Manager Console

Another handy Nuget command for the Package Manager Module:
PM>Get-Package -Filter React -ListAvailable

Updating jQuery Using Nuget to a Version Less than 2.0

jQuery 2 is out and whilst I’m keen to embrace new things, a lot of 3rd party libraries have jQuery 1.* as a dependency. If you just update jQuery using Nuget, it brings down jQuery 2.*, which may not be what you want.

So, the easiest way to target a specific version is to using the following command with the Package Manager Console (I chose 1.10.1 as an example):
PM> Install-Package jQuery -Version 1.10.1