VS2015 – “NuGetPackage”包没有正确加载
刚刚打开VS 2015 Enterprise RTM,打开了一个现有的工作项目,出现如下错误:
Microsoft Visual Studio
'NuGetPackage'包没有正确加载。
问题可能是由configuration更改或安装另一个扩展引起的。 您可以通过检查文件
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 'Microsoft.Dev14.VsixTemplatesPackage.443cca91-ec20-41e5-a165-f28e56b89650' 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 'Microsoft.VisualStudio.TeamFoundation.TeamExplorer.Extensions' 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>
这将提示重复的扩展名,但在扩展pipe理器中似乎不是这种情况。
这是在一台也安装了VS2013的机器上。 它还没有安装VS2015的任何预览/ RC版本。
通过扩展和更新完全删除NuGet,重新启动VS,然后通过扩展和更新重新安装NuGet解决了我的问题。 一个完整的VS重新安装是没有必要的。
更新Nuget到最新版本似乎已经解决了这个问题。
-
工具>扩展和更新
-
更新> Visual Studio库
-
点击Nuget Package Manager选项上的更新
从MSDN网站完全干净安装Visual Studio Professional 2015后,我以pipe理员身份运行VS2015,从Tools -> NuGet Package Manager... -> Package Manager Console
打开程序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。
现在,当打开包pipe理器控制台时,Powershell会正确加载,并且每件事情都是好的。 非常感谢!
记住
NuGet包pipe理器的重新安装似乎并没有删除保存在c:\ users \ name \ AppData \ Roaming \ NuGet中的现有NuGet.Config文件!
我有一个缺less'packageSources'部分(为什么,我不知道),但由于这个文件没有重新创buildNuGet仍然没有工作!
因此,无论是手动input此部分或删除此configuration文件,然后通过扩展和更新重新安装NuGet将重新创build一个新的!
从这个文件夹删除所有文件C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\imf5jbeu.eak
似乎已经为我工作。
似乎VS2015中的nuget设置为只显示微软包。 要能够在nuget.org中search所有软件包,请转到工具>选项> NuGet软件包pipe理器>软件包源,单击添加,将nuget.org作为名称,并将https://www.nuget.org/api/v2/作为源,然后单击确定。; 现在在Nuget Package Manager中,您可以selectnuget.org(或All)作为程序包源,您将能够search所有程序包(不仅是来自Microsoft的程序包)。
我有同样的问题,解决了已经提到的解决scheme,但需要更多的尝试。 卸载并安装NuGetPackage扩展后,需要完全重新启动VS,并且在我的系统上它不工作,直到我closures我打开的解决scheme。 希望NuGetPackage扩展在不久的将来会更加稳定。
当使用nuget包将项目从Vx20XX升级到VS2015时,nuget包可能会有问题。
错误消息示例:此项目引用此计算机上缺less的NuGet程序包。 启用NuGet软件包还原以下载它们。 有关更多信息,请参阅http://go.microsoft.com/fwlink/?LinkID=322105 。
我解决了我的问题写一个小程序,做MSBuild的集成软件包还原与自动软件包还原
您可以在这里下载该工具的可执行文件。
请让我知道结果:-)!
代码作为参考:
<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"; } } }
进入 :
工具
扩展和更新
在右侧的Nuget Package Manager
上的search框中插入并设置(完整设置)。
接下来你将在工具部分有pipe理Nuget包。
我发现这在谷歌,得到了类似的错误:'NuGetPackage'包没有正确加载。
读取文件xxx时发生错误。 有重复的包。
检查每个项目中的packages.config文件,并从中删除重复的包行,它应该工作。