VS2015 - 'NuGetPackage'包未正确加载

时间:2015-07-20 16:17:10

标签: nuget visual-studio-2015

刚刚开放VS 2015 Enterprise RTM,打开了现有的工作项目,收到以下错误:

        

Microsoft Visual Studio

           

'NuGetPackage'包未正确加载。

     

问题可能是由配置更改或安装其他扩展程序引起的。您可以通过检查文件C:\Users\REDACTED\AppData\Roaming\Microsoft\VisualStudio\14.0\ActivityLog.xml来获取更多信息。

     

重新启动Visual Studio可以帮助解决此问题。

     

继续显示此错误消息?

           

[是] [否]

     

重启没有帮助。我检查了日志文件,发现以下与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>

这会建议重复的扩展名,但扩展管理器中的情况似乎并非如此。

这是在安装了VS2013的机器上。它还没有安装任何VS2015的预览/ RC版本。

11 个答案:

答案 0 :(得分:62)

通过扩展和更新完全删除NuGet,重新启动VS然后通过扩展和更新重新安装NuGet为我解决了这个问题。不需要完整的VS重新安装。

答案 1 :(得分:28)

将Nuget更新到最新版本似乎解决了这个问题。

  1. 工具&gt;扩展和更新

  2. 更新&gt; Visual Studio Gallery

  3. 点击Nuget Package Manager选项更新

答案 2 :(得分:6)

从MSDN网站完全安装Visual Studio Professional 2015后,我以管理员身份运行VS2015,从Tools -> NuGet Package Manager... -> Package Manager Console打开了包管理器控制台,我收到此错误:

"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"

按照上述步骤

1)使用Tools -> Extensions and Updates...卸载NuGet Package Manager for Visual Studio 2015

2)重新启动Visual Studio。

3)使用Tools -> Extensions and Updates... 重新安装 NuGet Package Manager for Visual Studio 2015

4)重新启动Visual Studio。

现在,当我打开软件包管理器控制台时,Powershell正确加载并且每件事情都很好。非常感谢你!

答案 3 :(得分:5)

请记住

重新安装NuGet Package Manager NOT 似乎删除了c:\ users \ name \ AppData \ Roaming \ NuGet中保存的现有NuGet.Config文件!

我失去了'packageSources'部分(为什么,我不知道)但是由于这个文件没有被重新创建,NuGet仍然没有用!

因此,要么手动输入此部分或删除此配置文件,请通过扩展和更新重新安装NuGet,这将重新创建一个全新的!

答案 4 :(得分:2)

删除此文件夹C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\imf5jbeu.eak中的所有文件似乎对我有用。

答案 5 :(得分:2)

似乎VS2015中的nuget设置为仅显示微软软件包。为了能够在nuget.org中搜索所有包,请转到工具&gt;选项&gt; NuGet包管理器&gt; Package Sources,单击add,将nuget.org作为Name,将https://www.nuget.org/api/v2/作为Source,然后单击OK。 现在在Nuget Package Manager中,您可以选择nuget.org(或All)作为Package源,您将能够搜索所有包(不仅是来自microsoft的包)。

答案 6 :(得分:0)

我遇到了同样的问题并用已经提到的解决方案解决了它,但需要更多的尝试。卸载并安装NuGetPackage扩展后,必须重新启动VS,在我关闭打开的解决方案之前,我的系统无法正常工作。希望NuGetPackage扩展在不久的将来变得更加稳定。

答案 7 :(得分:0)

使用nuget软件包从Vx20XX升级到VS2015的项目时,您可能会遇到nuget软件包问题。

错误消息示例: 此项目引用此计算机上缺少的NuGet包。启用NuGet Package Restore以下载它们。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=322105

我修复了编写一个MSBuild-Integrated package restore vs. Automatic Package Restore

的小程序的问题

您可以下载工具here的可执行文件。

请让我知道结果:-)!

Tool screenshot

代码作为参考:

<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";
        }

    }
}

答案 8 :(得分:0)

进入:

  

工具
  扩展和更新

在右侧Nuget Package Manager的搜索框中插入 并设置(完整设置)。

然后,您将在“工具”部分中拥有“管理Nuget包”。

答案 9 :(得分:0)

我在谷歌上发现了这个,得到了类似的错误:'NuGetPackage'包没有正确加载。

  

读取文件xxx时发生错误。有重复   包。

检查每个项目中的packages.config文件,并从中删除重复的包行,它应该可以工作。

答案 10 :(得分:0)

重启Visual Studio(2017)为我解决了这个问题。