Visual Studio 2015无法进行Package Restore的原因和解决方案

这篇文章是记录在我的当前电脑上面,安装Visual Studio 2015 Community Edition出现的无法进行Package Restore的问题,很可能在你的电脑上面无法重现。我的环境是

1.Windows 7  x64

2.已经安装了Visual Studio 2013

3.已经手工地安装过dnvm 和dnx

 

问题现象:

为了更好地了解和学习一下最新的ASP.NET 5 , MVC 6等一些特性,在当前电脑上面安装了Visual Studio 2015 Community Edition。安装之前,确认过它是可以与当前的Visual Studio 2013并行(Side by side)运行的。

Visual Studio 2015无法进行Package Restore的原因和解决方案_第1张图片

按照默认的设置安装完成后,启动Visual Studio 2015,创建了一个最简单的应用程序,但是无法编译通过,查看输出窗口,得到如下的错误消息

PATH=.\node_modules\.bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External;%PATH%;C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\git
C:\Users\chenxizhang\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta7\bin\dnx.exe "C:\Users\chenxizhang\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta7\bin\lib\Microsoft.DNX.PackageManager\Microsoft.DNX.PackageManager.dll" restore "c:\users\chenxizhang\documents\visual studio 2015\Projects\ConsoleApp1\src\ConsoleApp1" -s "C:\Program Files (x86)\Microsoft Web Tools\DNU"
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.DNX.PackageManager' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.DNX.PackageManager'
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.Load(AssemblyName assemblyName)
   at Microsoft.Dnx.Host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env, FrameworkName targetFramework)
   at Microsoft.Dnx.Host.RuntimeBootstrapper.ExecuteAsync(String[] args, FrameworkName targetFramework)
   at Microsoft.Dnx.Host.RuntimeBootstrapper.Execute(String[] args, FrameworkName targetFramework)
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

 

看这个错误提示,是因为找不到对应的dnx(运行时)中的Package Manager这个组件。果然如此吗?当前我的电脑上面,已经安装了好几个runtime(注意,这是我自己手工安装的,前期做其他的实验。Visual Studio 2015在安装的过程中也会自己安装dnvm和对应的dnx)

image

Visual Studio 2015默认会调用最新版本的runtime(目前是1.0.0-beta 7),并且尝试用它进行Package Restore。我找到对应的目录中去看,确实没有Microsoft.DNX.PackageManager这个文件夹。

image

但是奇怪的是,稍早的版本(例如1.0.0-beta 5)确是存在这个目录和对应的DLL

image

 

解决方案

目前尚不清楚为什么beta7反而有这个问题,但要解决这个问题,暂时先用beta 5我觉得也是可以接受的

Visual Studio 2015无法进行Package Restore的原因和解决方案_第2张图片

image

 

为了简便起见,我们也可以将其他的runtime先删除掉,只留下beta5。这样就不需要每个项目都去设置了。

image

当然,相信以后1.0.0正式发布之后,这些问题是可以解决掉的

你可能感兴趣的:(Visual Studio 2015无法进行Package Restore的原因和解决方案)