I had set up the MvcBuildViews element to true so my MVC 3 project would compile the views as well.
However, because of that, our build server is failing the builds. I had searched around for possible causes but my problem seems to be different from the common ones:
Error: _Layout.cshtml(xx): The name "Element" does not exist in the current context.
In this case Element is a reference we’re making to a Helper view, calling one of its methods.
Any idea what the problem may be?
(by the way, the build server is TFS2010)
I have found the issue underlying my problem. I’m updating here so that everyone can learn from my situation.
The TFS build server kept failing so for the sake of moving on with the project, I just edited the MVC project so it wouldn’t compile the views on the server, but just on our dev machines. In order to do that, I changed from
to
When we took this all and deployed the builds to an actual environment, I found that the very same error popped out on our deployed environment. I went and took a look into the deployment package, only to find that my helper view
Element.cshtmlwas not in theApp_Codefolder, where it was supposed to be.I opened the project file up again and searched for the reference to that file. I found that in that specific reference, the setting was
instead of
I just changed the way the reference was made (dunno how it got that way) and everything worked like a charm.
Moral of the story: Pay attention to what the error says.
Now I’m curious about why wouldn’t it fail on our dev machines. Probably because the build server has a different output folder and so it wouldn’t find the .cshtml in the output? Maybe that’s something for some other question…