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.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>