【问题标题】:Visual Studio 2015 New MVC Project - the mvc does not exist in Microsoft.AspnetVisual Studio 2015 新 MVC 项目 - Microsoft.Aspnet 中不存在 mvc
【发布时间】:2016-01-01 10:30:40
【问题描述】:

我在 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 类型或命名空间名称“Mvc”不存在于 命名空间“Microsoft.AspNet”(您是否缺少程序集引用?)

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

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

  1. 已修复 VS 2015。
  2. 从 Nuget 卸载并安装 Install-Package Microsoft.AspNet.Mvc
  3. 复制本地 = True
  4. System.web.MVC 已被引用。
  5. web.config的版本全都5.2.3.0

【问题讨论】:

  • 重新打开项目可以解决您的问题。
  • 我已尝试重新打开并卸载和加载项目,但我仍然收到该错误

标签: asp.net-mvc asp.net-mvc-5 visual-studio-2015


【解决方案1】:

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

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

【讨论】:

  • 我已尝试重新打开并卸载和加载项目,但我仍然收到该错误。在我的应用程序中可能存在包使用其他版本的情况,但它也发生在我的默认新 Visual Studio 2015 项目中
【解决方案2】:

我在 %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. 下载网络安装程序设置文件并在下载的目录中运行以下命令

      vs_community.exe /uninstall /force

    3. 卸载后确认没有安装VS相关的文件软件,重启电脑

    4. 使用 Web 安装程序安装了新的 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 解决方案,虽然在启动时需要一些时间,但之后它可以工作。

    【讨论】:

      【解决方案4】:

      我遇到了这个错误,并且能够通过编辑 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 目录中

      希望这会有所帮助!

      【讨论】:

      • 遇到了同样的问题。到目前为止,建议的解决方案都没有奏效。任何其他建议
      • @BrilBroeder 你有没有试过重新安装visual studio,我已经发布了解决方案?
      • @ShanKhan re-install 做到了。谢谢。但是VS2015在Win10上还是很慢。但这是我有时间时必须研究的另一个问题:-)
      • @BrilBroeder 你试过重置用户数据吗?它可能会有所帮助。有时扩展会产生意想不到的行为
      • 是的,没做好。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多