VS2015 - The 'NuGetPackage' package did not load correctly

NugetVisual Studio-2015

Nuget Problem Overview


Just opened up VS 2015 Enterprise RTM, opened up an existing working project, getting the following error:

> --------------------------- > Microsoft Visual Studio > --------------------------- > The 'NuGetPackage' package did not load correctly. > > The problem may have been caused by a configuration change or by the installation of another extension. You can get more information by examining the file C:\Users\REDACTED\AppData\Roaming\Microsoft\VisualStudio\14.0\ActivityLog.xml. > > Restarting Visual Studio could help resolve this issue. > > Continue to show this error message? > --------------------------- > [Yes] [No] > ---------------------------

Restarting didn't help. I've examined the log file, and found the following sections relevant to nuget:

<entry>
  <record>555</record>
  <time>2015/07/20 16:06:34.364</time>
  <type>Error</type>
  <source>Extension Manager</source>
  <description>Extension will not be loaded because an extension with the same ID 
     &apos;Microsoft.Dev14.VsixTemplatesPackage.443cca91-ec20-41e5-a165-f28e56b89650&apos; 
     is already loaded at C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\COMMON7\IDE\
     EXTENSIONS\G2URSPAC.VAZ\...</description>
  <path>C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\COMMON7\IDE\EXTENSIONS\
     NUGETIFIEDEXTENSIBILITYTEMPLATES\</path>
</entry>
<entry>
  <record>556</record>
  <time>2015/07/20 16:06:34.364</time>
  <type>Error</type>
  <source>Extension Manager</source>
  <description>Extension will not be loaded because an extension with the same ID
     &apos;Microsoft.VisualStudio.TeamFoundation.TeamExplorer.Extensions&apos; is already
     loaded at C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\COMMON7\IDE\EXTENSIONS\
     B1NUOYPH.H2N\...</description>
  <path>C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\COMMON7\IDE\COMMONEXTENSIONS\
     MICROSOFT\TEAMFOUNDATION\TEAM EXPLORER\</path>
</entry>

Which would suggest a duplicate extension, but this doesn't seem to be the case in the extensions manager.

This is on a machine that also has VS2013 installed. It has not had any of the preview/RC builds of VS2015 installed ever.

Nuget Solutions


Solution 1 - Nuget

Completely removing NuGet via Extensions and Updates, restarting VS then re-installing NuGet via Extensions and Updates solved the issue for me. A full VS reinstall was not necessary.

Solution 2 - Nuget

Updating Nuget to the latest version seems to have solved the problem.

  1. Tools > Extensions and Updates

  2. Updates > Visual Studio Gallery

  3. Click Update on the Nuget Package Manager option

Solution 3 - Nuget

After a completely clean install of Visual Studio Professional 2015 from the MSDN Website, I ran VS2015 as Administrator, opened up the Package Manager Console from Tools -> NuGet Package Manager... -> Package Manager Console and I received this error:

"Windows PowerShell updated your execution policy successfully, 
but the setting is overridden by a policy defined at a more 
specific scope. Due to the override, your shell will retain its 
current effective execution policy of Unrestricted. 
Type "Get-ExecutionPolicy -List" to view your execution policy 
settings. For more information please see "Get-Help Set-ExecutionPolicy"

By following the above steps to

  1. Use Tools -> Extensions and Updates... to uninstall NuGet Package Manager for Visual Studio 2015.

  2. Restart Visual Studio.

  3. Use Tools -> Extensions and Updates... to re-install NuGet Package Manager for Visual Studio 2015.

  4. Restart Visual Studio.

Now when I open up the Package Manager Console, Powershell loads correctly and every thing is good. Thanks so much for this!

Solution 4 - Nuget

Bear in mind

A reinstall of the NuGet Package Manager does NOT seem to remove the existing NuGet.Config file held in c:\users\name\AppData\Roaming\NuGet!

Mine had a missing 'packageSources' section (why, I don't know) but since this file was not recreated NuGet still didn't work!

So either manually enter this section or remove this config file, then reinstall NuGet through the Extensions and Updates which will recreate a brand new one!

Solution 5 - Nuget

Deleting all the files from this folder C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\imf5jbeu.eak seem to have worked for me.

Solution 6 - Nuget

It seems that nuget in VS2015 is set up to show only microsoft packages. To be able to search all packages in nuget.org go to Tools > Options > NuGet Package Manager > Package Sources, click add, put nuget.org as Name and https://www.nuget.org/api/v2/ as Source, then click OK. Now in Nuget Package Manager you can select nuget.org (or All) as Package source and you will be able to search for all packages (not only the ones coming from microsoft).

Solution 7 - Nuget

Go into :

> Tools
Extensions and Updates

Insert on the search box on the right Nuget Package Manager and set it up (full setup) .

Following that you would have the Manage Nuget Packages in the Tools section .

Solution 8 - Nuget

I had the same problem and solved it with the already mentioned solution but needed more attempts. It's necessary to restart VS completely after uninstalling and installing the NuGetPackage extension and on my system it was not working until I closed my opened solution. Hopefully NuGetPackage extension gets more stable in the near future.

Solution 9 - Nuget

When upgrading projects with nuget packages from Vx20XX to VS2015, you might have a problem with nuget packages.

Example of error message: 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.

I fixed my problem writing a little program that do MSBuild-Integrated package restore vs. Automatic Package Restore

You can download executable of the tool here.

Please let me know the result :-) !

Tool screenshot

Code as reference:

<Window x:Class="FixNuGetProblemsInVs2015.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:FixNuGetProblemsInVs2015"
        mc:Ignorable="d"
        Title="Fix NuGet Packages problems in Visual Studio 2015 (By Eric Ouellet)" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"></ColumnDefinition>
            <ColumnDefinition Width="10"></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>

        <TextBlock Grid.Row="0" Grid.Column="0">Root directory of projects</TextBlock>
        <Grid Grid.Row="0" Grid.Column="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
            </Grid.ColumnDefinitions>

            <TextBox Grid.Column="0" Name="DirProjects"></TextBox>
            <Button Grid.Column="1" VerticalAlignment="Bottom" Name="BrowseDirProjects" Click="BrowseDirProjectsOnClick">Browse...</Button>
        </Grid>

        <!--<TextBlock Grid.Row="1" Grid.Column="0">Directory of NuGet Packages</TextBlock>
        <Grid Grid.Row="1" Grid.Column="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition></ColumnDefinition>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
            </Grid.ColumnDefinitions>

            <TextBox Grid.Column="0" Name="DirPackages"></TextBox>
            <Button Grid.Column="1"  Name="BrowseDirPackages" Click="BrowseDirPackagesOnClick">Browse...</Button>
        </Grid>-->

        <TextBox Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Name="TxtLog" IsReadOnly="True"></TextBox>
        
        <Button Grid.Row="3" Grid.Column="0" Click="ButtonRevertOnClick">Revert back</Button>
        <Button Grid.Row="3" Grid.Column="2" Click="ButtonFixOnClick">Fix</Button>
    </Grid>
</Window>


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml;
using System.Xml.Linq;
using Application = System.Windows.Application;
using MessageBox = System.Windows.MessageBox;

/// <summary>
/// Applying recommanded modifications in section : "MSBuild-Integrated package restore vs. Automatic Package Restore"
/// of : http://docs.nuget.org/Consume/Package-Restore/Migrating-to-Automatic-Package-Restore
/// </summary>

namespace FixNuGetProblemsInVs2015
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();

			DirProjects.Text = @"c:\prj";
			// DirPackages.Text = @"C:\PRJ\NuGetPackages";
		}

		private void BrowseDirProjectsOnClick(object sender, RoutedEventArgs e)
		{
			FolderBrowserDialog dlg = new FolderBrowserDialog();
			dlg.SelectedPath = DirProjects.Text;
			if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
			{
				DirProjects.Text = dlg.SelectedPath;
			}
		}

		//private void BrowseDirPackagesOnClick(object sender, RoutedEventArgs e)
		//{
		//	FolderBrowserDialog dlg = new FolderBrowserDialog();
		//	dlg.SelectedPath = DirPackages.Text;
		//	if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
		//	{
		//		DirPackages.Text = dlg.SelectedPath;
		//	}
		//}

		// private string _dirPackages;

		private void ButtonFixOnClick(object sender, RoutedEventArgs e)
		{
			DoJob(false);
		}

		private void ButtonRevertOnClick(object sender, RoutedEventArgs e)
		{
			DoJob(true);
		}

		private void DoJob(bool revert = false)
		{
			TxtLog.Text = "";

			string dirProjects = DirProjects.Text;
			// _dirPackages = DirPackages.Text;

			if (!Directory.Exists(dirProjects))
			{
				MessageBox.Show("Projects directory does not exists: " + dirProjects);
				return;
			}

			//if (!Directory.Exists(_dirPackages))
			//{
			//	MessageBox.Show("Packages directory does not exists: " + _dirPackages);
			//	return;
			//}

			RecurseFolder(dirProjects, revert);
		}

		private void RecurseFolder(string dirProjects, bool revert = false)
		{
			if (revert)
			{
				Revert(dirProjects);
			}
			else
			{
				FixFolder(dirProjects);
			}

			foreach (string subfolder in Directory.EnumerateDirectories(dirProjects))
			{
				RecurseFolder(subfolder, revert);
			}
		}

		private const string BackupSuffix = ".fix_nuget_backup";
		
		private void Revert(string dirProject)
		{
			foreach (string filename in Directory.EnumerateFiles(dirProject))
			{
				if (filename.ToLower().EndsWith(BackupSuffix))
				{
					string original = filename.Substring(0, filename.Length - BackupSuffix.Length);
					if (File.Exists(original))
					{
						File.Delete(original);											
					}
					File.Move(filename, original);
					Log("File reverted: " + filename + " ==> " + original);
				}
			}
		}

		private void FixFolder(string dirProject)
		{
			BackupFile(System.IO.Path.Combine(dirProject, "nuget.targets"));
			BackupFile(System.IO.Path.Combine(dirProject, "nuget.exe"));

			foreach (string filename in Directory.EnumerateFiles(dirProject))
			{
				if (filename.ToLower().EndsWith(".csproj"))
				{
					FromProjectFileRemoveNugetTargets(filename);
				}
			}
		}

		private void BackupFile(string path)
		{
			if (File.Exists(path))
			{
				string backup = path + BackupSuffix;
                if (!File.Exists(backup))
				{
					File.Move(path, backup);
					Log("File backup: " + backup);
				}
				else
				{
					Log("Project has already a backup: " + backup);
				}
			}
		}

		private void FromProjectFileRemoveNugetTargets(string prjFilename)
		{
			XDocument xml = XDocument.Load(prjFilename);

			List<XElement> elementsToRemove = new List<XElement>();
			
			foreach (XElement element in xml.Descendants())
			{
				if (element.Name.LocalName == "Import")
				{
					var att = element.Attribute("Project");
					if (att != null)
					{
						if (att.Value.Contains("NuGet.targets"))
						{
							elementsToRemove.Add(element);
						}
					}
				}

				if (element.Name.LocalName == "Target")
				{
					var att = element.Attribute("Name");
					if (att != null && att.Value == "EnsureNuGetPackageBuildImports")
					{
						elementsToRemove.Add(element);
					}
				}
			}

			if (elementsToRemove.Count > 0)
			{
				elementsToRemove.ForEach(element => element.Remove());
				BackupFile(prjFilename);
				xml.Save(prjFilename);
				Log("Project updated: " + prjFilename);
			}
		}

		private void Log(string msg)
		{
			TxtLog.Text += msg + "\r\n";
		}

	}
}

Solution 10 - Nuget

I found this on google, got a similar error: The 'NuGetPackage' package did not load correctly.

> An error occurred while reading file xxx. There are duplicate > packages.

Check the packages.config file in every project, and remove the duplicate package line from it, and it should work.

Solution 11 - Nuget

Restarting Visual Studio (2017) fixed this for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPhonicUKView Question on Stackoverflow
Solution 1 - NugetPhonicUKView Answer on Stackoverflow
Solution 2 - NugetAndrius NaruševičiusView Answer on Stackoverflow
Solution 3 - NugetbradykeyView Answer on Stackoverflow
Solution 4 - NugetMarcelView Answer on Stackoverflow
Solution 5 - NugetCoOlView Answer on Stackoverflow
Solution 6 - NugetDariusz SzczepaniakView Answer on Stackoverflow
Solution 7 - NugetJANView Answer on Stackoverflow
Solution 8 - NugetAndreasView Answer on Stackoverflow
Solution 9 - NugetEric OuelletView Answer on Stackoverflow
Solution 10 - Nugetlive-loveView Answer on Stackoverflow
Solution 11 - NugetYokyView Answer on Stackoverflow