Visual Studio 2015新MVC项目 - Microsoft.Aspnet中不存在mvc

问题描述 投票:9回答:4

我在Visual Studio 2015中遇到错误我使用的是Windows 8.1和visual studio 2013,所有使用asp.net MVC 5的项目都正常运行并且没有任何错误。

自从我安装了Windows 10和visual studio 2015以来,我的整个ASP.NET MVC 5项目都运行不正常。

我在visual studio 2015中创建了新的默认模板来检查它们。我在这些新项目上也遇到了同样的错误。

我得到错误:

CS0234命名空间“Microsoft.AspNet”中不存在类型或命名空间名称“Mvc”(您是否缺少程序集引用?)

当前上下文中不存在名称“布局”。

**我已经尝试过的事情:**

  1. 修复VS 2015。
  2. 从Nuget卸载并安装了Install-Package Microsoft.AspNet.Mvc
  3. 复制Local = True
  4. System.web.MVC已经被引用。
  5. web.config的版本都放在5.2.3.0中
asp.net-mvc asp.net-mvc-5 visual-studio-2015
4个回答
4
投票

我在%AppData%\ Microsoft \ VisualStudio \ 14.0 \ ActivityLog.xml中收到此错误:

<type>Error</type>
<source>Editor or Editor Extension</source>
<description>System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---&gt; System.ArgumentException: Item has already been added. Key in dictionary: &apos;RazorSupportedRuntimeVersion&apos;  Key being added: &apos;RazorSupportedRuntimeVersion&apos;&#x000D;&#x000A;   at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)&#x000D;&#x000A;   at System.Collections.Hashtable.Add(Object key, Object value)&#x000D;&#x000A;   at System.Collections.Specialized.HybridDictionary.Add(Object key, Object value)&#x000D;&#x000A;   at Microsoft.VisualStudio.Utilities.PropertyCollection.AddProperty(Object key, Object property)&#x000D;&#x000A;   at Microsoft.VisualStudio.Html.Package.Razor.RazorVersionDetector.Microsoft.Html.Editor.ContainedLanguage.Razor.Def.IRazorVersionDetector.GetVersion(ITextBuffer textBuffer)&#x000D;&#x000A;   at Microsoft.Html.Editor.ContainedLanguage.Razor.RazorUtility.TryGetRazorVersion(ITextBuffer textBuffer, Version&amp; razorVersion)&#x000D;&#x000A;   at Microsoft.Html.Editor.ContainedLanguage.Razor.RazorErrorTagger..ctor(ITextBuffer textBuffer)&#x000D;&#x000A; 

我运行C:\“Program Files(x86)”\“Microsoft Visual Studio 14.0”\ Common7 \ IDE \ devenv.exe / resetuserdata并修复了它。

取自Exception when opening a cshtml file


3
投票

我按照这些步骤完全重新安装Visual Studio 2015,解决了这个问题。修复没有工作

  1. 运行命令 C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ devenv.exe / resetuserdata
  2. 下载Web安装程序安装文件,然后在下载的目录中运行以下命令 vs_community.exe / uninstall / force
  3. 卸载后我确保没有安装与VS相关的文件软件并重新启动PC
  4. 使用Web Installer安装新的Visual Studio。
  5. 再次运行该命令。 C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ devenv.exe / resetuserdata
  6. Visual Studio中提供了更新,安装它们 - 重新启动Visual Studio
  7. 现在打开任何asp.net mvc解决方案,虽然在开始时需要时间,但之后就可以了。

1
投票

我在Visual Studio 2015中遇到了同样的问题,每次打开我的ASP.NET 5.0项目时都会遇到错误,但是当我再次重新打开应用程序时,错误就会消失。

顺便说一下,问题似乎是关于正确的版本控制,例如,如果您使用的是ASP.NET 5.0的Beta 7.0,也许某些软件包仍然使用以前的版本,如Beta 5.0,...


0
投票

我遇到了这个错误,并且能够通过编辑web.config的runtime/assemblyBinding部分来解决它,如下所示:

<!-- Original //-->
<dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>

<!-- Changed to... //-->
 <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
  </dependentAssembly>

这可能位于主web.config文件和/或Views目录中的文件中

希望这可以帮助!

© www.soinside.com 2019 - 2024. All rights reserved.