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
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
to
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true' AND '$(BuildingInsideVisualStudio)'=='true'">
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.cshtml was not in the App_Code folder, 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
<None Include="App_Code\Element.cshtml" />
instead of
<Content Include="App_Code\Element.cshtml" />
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...
@helper PutElement() { @Element.Method(param, param, param) }