Asp.net-Mvc

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

  • March 6, 2018

我在 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. 複製本地 = True
  4. System.web.MVC 已被引用。
  5. web.config的版本都在5.2.3.0

我按照這些步驟完全重新安裝了解決問題的 Visual Studio 2015。修復沒用

  1. 執行命令

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

  1. 下載 Web 安裝程序設置文件並在下載的目錄中執行以下命令

vs_community.exe /解除安裝 /force

  1. 解除安裝後我確保沒有安裝與VS相關的文件軟體並重新啟動PC
  2. 使用 Web 安裝程序安裝了新的 Visual Studio。
  3. 再次執行該命令。

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

  1. 更新在 Visual Studio 中可用,安裝它們 - 重新啟動 Visual Studio
  2. 現在打開任何 asp.net mvc 解決方案,雖然在啟動時需要一些時間,但之後它就可以工作了。

我在 %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. ---> System.ArgumentException: Item has already been added. Key in dictionary: 'RazorSupportedRuntimeVersion'  Key being added: 'RazorSupportedRuntimeVersion'
   at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
   at System.Collections.Hashtable.Add(Object key, Object value)
   at System.Collections.Specialized.HybridDictionary.Add(Object key, Object value)
   at Microsoft.VisualStudio.Utilities.PropertyCollection.AddProperty(Object key, Object property)
   at Microsoft.VisualStudio.Html.Package.Razor.RazorVersionDetector.Microsoft.Html.Editor.ContainedLanguage.Razor.Def.IRazorVersionDetector.GetVersion(ITextBuffer textBuffer)
   at Microsoft.Html.Editor.ContainedLanguage.Razor.RazorUtility.TryGetRazorVersion(ITextBuffer textBuffer, Version& razorVersion)
   at Microsoft.Html.Editor.ContainedLanguage.Razor.RazorErrorTagger..ctor(ITextBuffer textBuffer)
 

我執行了 C:"Program Files (x86)""Microsoft Visual Studio 14.0"\Common7\IDE\devenv.exe /resetuserdata 並修復了它。

打開 cshtml 文件時取自異常

引用自:https://stackoverflow.com/questions/32937222