Compiling MVC 3 Views Using Help Helpers on the Build Server

I set the element MvcBuildViews

to true so that my MVC 3 project will compile views as well.

However, because of this, our build server is not performing builds. I've searched for possible reasons, but my problem seems to be different from the usual ones:

Mistake: _Layout.cshtml(xx): The name "Element" does not exist in the current context.

In this case, Element

is the link we create for the Helper view by calling one of its methods.

Any idea what the problem might be?

(TFS2010 build server by the way)

+3


source to share


2 answers


I found the problem at the root of my problem. I am updating here so that everyone can learn from my situation.

The TFS build server was failing all the time, so in order to get to the project I just edited the MVC project so that it doesn't build views on the server, but only on our machines. To do this, 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 assemblies in a real environment, I found that the same error appeared in our deployed environment. I went and looked into the deployment package, only to find that my subview Element.cshtml

was not in the folder App_Code

where it should have been.

I opened the project file again and looked for a link to that file. I found that in this particular link the setting was



<None Include="App_Code\Element.cshtml" />

      

instead

<Content Include="App_Code\Element.cshtml" />

      

I just changed the way the link was created (not sure how it turned out) and everything works like a charm.

Moral of the story: Pay attention to what the error says.

Now I'm curious why not fail on our machines. Probably because the build server has a different output folder and so it won't find .cshtml in the output? Maybe something for another question ...

+5


source


Have you seen this post? http://haacked.com/archive/2011/05/09/compiling-mvc-views-in-a-build-environment.aspx



0


source







All Articles