首页 文章

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

提问于
浏览
9

我在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”(您是否缺少程序集引用?)

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

我已经尝试过的事情:

  • 修复VS 2015 .

  • 从Nuget卸载并安装了Install-Package Microsoft.AspNet.Mvc

  • Copy Local = True

  • 已经引用了System.web.MVC .

  • web.config的版本都放在5.2.3.0中

4 回答

  • 4

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

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

  • 1

    我按照这些步骤完全 re-install Visual Studio 2015解决了这个问题 . 修复没有工作

    • 运行命令

    C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ devenv.exe / resetuserdata

    • 下载Web安装程序安装文件,并在下载的目录中运行以下命令

    vs_community.exe / uninstall / force

    • 卸载后我确保没有安装与VS相关的文件软件并重新启动PC

    • 使用Web Installer安装了新的Visual Studio .

    • 再次运行该命令 .

    C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ devenv.exe / resetuserdata

    • 在Visual Studio中可以使用更新,安装它们 - 重新启动Visual Studio

    • 现在打开任何asp.net mvc解决方案,虽然在开始时需要时间,但之后就可以了 .

  • 3

    我在%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

  • 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目录中的文件中

    希望这可以帮助!

相关问题