在Windows 8.1上全新安装Visual Studio 2013后,ASP.NET MVC Razor错误

问题描述:

我最近买了一台新笔记本电脑,并重新安装了Visual Studio 2013 Professional.安装后,我要做的第一件事是确保将Nuget设置为自动下载丢失的软件包.

I recently got a new laptop and did a fresh installation of Visual Studio 2013 Professional. After installation, the first thing I did was to make sure that Nuget was set to automatically download missing packages.

我现在正在尝试在购买新笔记本电脑之前使用相同的大型解决方案,但是却遇到了一些奇怪的错误,经过许多小时的研究,这些错误仍无法解决.

I'm now trying to work on the same large solution I was using before getting my new laptop, but I'm getting some strange errors that I haven't been able to resolve after many hours of research.

该问题最明显的症状是我在Razor视图上看到许多错误.这些是错误类型:

The most obvious symptom of the issue is that I see many errors on Razor views. They are these types of errors:

  • 功能'lambda表达式'不能使用,因为它不是ISO-2 C#语言规范的一部分

  • Feature 'lambda expression' cannot be used because it is not part of the ISO-2 C# language specification

功能匿名类型"不能使用,因为它不属于 ISO-2 C#语言规范

Feature 'anonymous types' cannot be used because it is not part of the ISO-2 C# language specification

功能隐式键入局部变量"不能使用,因为它 不是ISO-2 C#语言规范的一部分

Feature 'implicitly typed local variable' cannot be used because it is not part of the ISO-2 C# language specification

功能扩展方法"不能使用,因为它不是其中的一部分 ISO-2 C#语言规范

Feature 'extension method' cannot be used because it is not part of the ISO-2 C# language specification

另一个症状是,如果我尝试添加新视图,则MVC项均不可用:例如,没有.cshtml项.但是,如果我创建一个新的解决方案,则这些项目将按预期提供.

Another symptom is that if I try to add a new view, none of the MVC items are available: for example, no .cshtml items. However, if I create a new solution, these items are available as expected.

我已随全新安装一起更新到Visual Studio 2013 Update 3.该解决方案使用MVC 4和Razor2.我检查了web.config,没有发现任何错误-我想要的Razor和MVC的版本是正确的.

I updated to Visual Studio 2013 Update 3 along with the fresh installation. The solution uses MVC 4 and Razor 2. I've checked the web.config and see nothing wrong - the version of Razor and MVC I want are correct.

尽管有这些错误,我的项目还是成功构建.构建后,所有隐式键入局部变量"错误都会消失几分钟,然后返回.另一个人正在使用旧笔记本电脑上的相同解决方案,并且没有遇到这些问题.

Despite these errors, my project builds successfully. After the build, all of the 'implicitly typed local variable' errors disappear for a few minutes, then return. Another person is working on the same solution on an old laptop and is not experiencing these issues.

我希望有人能提供帮助.我需要解决此问题,因为缺少有用的Intellisense会损害我的工作效率.

I'm hoping somebody can help. I need to resolve this issue because the lack of useful Intellisense is hurting my productivity.

我仍然有旧笔记本电脑,因此我比较了旧计算机上的设置和文件结构.文件结构非常不同.我没有在新计算机上使用相同的根目录.打开旧版本的解决方案时,我从旧计算机上复制了文件,并遇到TFS绑定错误.我进行了一些研究,以弄清楚如何修复绑定,这使我得以管理工作区.我删除了现有的工作区,并添加了一个带有正确路径的新工作区,该路径指向笔记本电脑上的解决方案.源代码控制盒开始疯狂复制文件.完成后,我遇到很多冲突,说已经存在一个非版本控制文件或同名可写文件...",我选择为每个文件覆盖本地文件,然后关闭Visual Studio并重新加载该项目.问题解决了.

I still have my old laptop, so I compared the settings and file structure on my old machine. The file structure was very different. I was not using the same root directory on the new machine. I copied the files from my old machine and got TFS binding errors when I opened the old version of the solution. I did some research to figure out how to fix the bindings, which led me to managing the workspaces. I removed the existing workspace and added a new one with the correct paths to the solutions on my laptop. A source control box started frantically copying files. When it was finished, I had a lot of conflicts that said "A non version controlled file or or writable file by the same name already exists..." I chose to overwrite the local file for each one, then closed Visual Studio and reloaded the project. Problem solved.

我相信我的问题的根本原因是无效的工作空间.如果我先修复了工作区,我可能可以避免从旧计算机上复制文件.

I believe that the root cause of my issue was the invalid workspace. I probably could have avoided copying files from my old machine if I had fixed the workspace first.