asp.net-mvc 临时目录中自动生成的“App_Web********.cs”文件导致构建错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21418091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Auto-generated "App_Web********.cs" files in temp directory causing build errors
提问by Graham
So this has been bugging me for a while, but sometimes in my Visual Studio 2013 ASP.NET MVC4 project, I will delete an unused ViewModel class, and will get an error on the next compile that looks like this (for a ViewModel called "MostRecentMemberListing.cs" that I just deleted):
所以这一直困扰着我一段时间,但有时在我的 Visual Studio 2013 ASP.NET MVC4 项目中,我会删除一个未使用的 ViewModel 类,并且在下一次编译时会得到一个错误,看起来像这样(对于名为“ MostRecentMemberListing.cs”,我刚刚删除):
Error 9 The type or namespace name 'MostRecentMemberListing' does not exist in the namespace 'MembershipCenter.ViewModels' (are you missing an assembly reference?) c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\temp\3e932790\42b7ff67\App_Web_cvlbfbci.1.cs 29 MembershipCenter
错误 9 命名空间“MembershipCenter.ViewModels”中不存在类型或命名空间名称“MostRecentMemberListing”(您是否缺少程序集引用?)c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files \temp\3e932790\42b7ff67\App_Web_cvlbfbci.1.cs 29 会员中心
If I double-click the error in the "Error List" panel of VS, it opens a file located in this path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\temp\3e932790\42b7ff67, which is a system-generated view file(?) with a classname of _Page_Views_Home_MostRecentMember_cshtml.
如果我双击 VS 的“错误列表”面板中的错误,它会打开一个位于以下路径中的文件:C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\temp\3e932790\42b7ff67,这是一个系统生成的视图文件(?),类名为_Page_Views_Home_MostRecentMember_cshtml.
I've tried deleting the weird file itself, as well as its containing folder, and ITS containing folder, all the way up the path to the tempfolder under Temporary ASP.NET Files. But everytime I re-compile my project all those folders and files are re-created in that directly and I get the same compile error.
我试着删除奇怪文件本身,以及其包含的文件夹,它包含的文件夹,一路向上的路径temp下的文件夹中Temporary ASP.NET Files。但是每次我重新编译我的项目时,所有这些文件夹和文件都会直接在其中重新创建,并且我得到相同的编译错误。
I am building my Views during the compilation, via <MvcBuildViews>true</MvcBuildViews>in the project file. If I turn this setting off, I can build + run just fine, but when I turn it back to true, the build error returns.
我正在编译期间通过<MvcBuildViews>true</MvcBuildViews>项目文件构建我的视图。如果我关闭此设置,我可以很好地构建 + 运行,但是当我将其转回 时true,构建错误将返回。
Has anyone encountered this error before? Is it related to IIS? I am running Local IIS, not IIS Express.
有没有人遇到过这个错误?它与IIS有关吗?我正在运行本地 IIS,而不是 IIS Express。
回答by Tommy
This is not related to IIS, local or otherwise. That long, strange file name you are seeing is the name the compiler gives to a view when it compiles it. What everything you have described is telling you is that you have a compilation error in one of your views. It could be mismatched HTML tags, a bad model property call, etc.
这与 IIS、本地或其他方式无关。你看到的那个长而奇怪的文件名是编译器在编译视图时给它的名称。您所描述的一切都告诉您,您的一个视图中存在编译错误。它可能是不匹配的 HTML 标签、错误的模型属性调用等。
Looking at your error message, you have a view in the /Views/Home/MostRecentMember.cshtml. Further, it appears that you are indeed either missing the namespace for your model declaration or declared the wrong namespace for the model that you are trying to send in.
查看您的错误消息,您在/Views/Home/MostRecentMember.cshtml. 此外,您似乎确实缺少模型声明的命名空间,或者为您尝试发送的模型声明了错误的命名空间。
Deleting the strangely named file will do nothing as when you rebuild, it will come back, most likely with a different name.
删除奇怪命名的文件不会做任何事情,因为当您重建时,它会回来,很可能以不同的名称。
回答by dibs487
I had this again today, there must be a bug in visual studio that causes it to try and compile all cshtml files in the views folder. Even if they are not part of the project. Your best bet is to click show all files in the solution explorer, find the rogue file and delete it.
我今天又遇到了这个问题,visual studio 中一定有一个错误,导致它尝试编译视图文件夹中的所有 cshtml 文件。即使他们不是项目的一部分。最好的办法是在解决方案资源管理器中单击显示所有文件,找到恶意文件并将其删除。
回答by vaibhav
I faced the same error after I changed the namespace of web application, I also renamed my solution and web project also. After lots of tricks and tips finally this solution worked for me.
更改 Web 应用程序的命名空间后,我遇到了同样的错误,我还重命名了我的解决方案和 Web 项目。经过大量技巧和技巧,最终这个解决方案对我有用。
- I inspected the app App_start files to find any reference to old namespace and found nothing
- I then searched web.config and Global.asax but no success.
Finally I searched in web.config listed under Views folder in solution and there I found reference of old name space under. Changed this to NewNamespaceand ran the application. This time it worked.
- 我检查了应用程序 App_start 文件以找到对旧命名空间的任何引用,但一无所获
- 然后我搜索了 web.config 和 Global.asax 但没有成功。
最后,我在解决方案中的 Views 文件夹下列出的 web.config 中搜索,在那里我找到了旧名称空间的参考。将其更改为NewNamespace并运行应用程序。这次成功了。
回答by wilaponce
I had this silly problem, if you notice the QuestionAnswer folder is an icon of a folder thats not included in the project and a file inside it references model that is non-existing or in the same state as the file, Excluded from project.
我遇到了这个愚蠢的问题,如果您注意到 QuestionAnswer 文件夹是一个未包含在项目中的文件夹的图标,并且其中的一个文件引用了不存在或与该文件处于相同状态的模型,则从项目中排除。
I had to select my project and show all files on solution explorer like image below

我必须选择我的项目并在解决方案资源管理器上显示所有文件,如下图所示

I then deleted the folder, file and the model that was also excluded from project causing build error. I hope the pictures help and happy coding.
然后我删除了也从项目中排除的文件夹、文件和模型,导致构建错误。我希望这些图片对您有所帮助并祝您编码愉快。
回答by Nitin A.
This error means that your view is using a model that cannot be found. This usually happens when you refactor/ remove model without updating views!
此错误意味着您的视图正在使用无法找到的模型。当您在不更新视图的情况下重构/删除模型时,通常会发生这种情况!
Fixing the reference to model in the affected view should solve this problem.
在受影响的视图中修复对模型的引用应该可以解决这个问题。
Else, try cleaning up ASP.Net temp directory: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
否则,尝试清理 ASP.Net 临时目录:C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
回答by N T
I have the same issuse and found the problem is the namespace of C# sensitive. Namespace in file .cshtml of view is upper "@model IEnumerable" and namespace space of class is Camel format "Abc.Def.Class".
我有同样的问题,发现问题是 C# 敏感的命名空间。视图文件 .cshtml 中的命名空间为上层“@model IEnumerable”,类的命名空间空间为 Camel 格式“Abc.Def.Class”。
I change the namespace in .cshtml to Camel format and it run.
我将 .cshtml 中的命名空间更改为 Camel 格式并运行。
回答by hogarth45
For others. It can also be forgetting the equals sign<%ThankyouMessage%>instead of<%=ThankyouMessage%>
为他人。它也可能忘记等号<%ThankyouMessage%>而不是<%=ThankyouMessage%>

