razor views are not giving compile time error [duplicate]

When i try to build my MVC4 Web Project. It doesn't recognize error in razor view when i do "Build" or "Re-Build".

Seems normal. Razor views are dynamically compiled by the ASP.NET runtime. If you want your views to be built at compile-time you could add the following option to your .csproj file:

<PropertyGroup>
    <MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>

You may take a look at the this article for more details.


I recommend you to add MmvcBuildViews tag as a child of the Release PropertyGroup tag so the views are only compiled when you compile in Release mode (or when you publish in Release mode). This way, your app is faster when you are debugging. And, you get compile-time checks before deploying (when you build on Release mode). In summary, you get the best of both worlds.

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <MvcBuildViews>true</MvcBuildViews>
  </PropertyGroup>

According to my experience, besides the true setting mentioned above, you still need to ensure below setting exist in your csproj file:

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>

By default it does not compile views. You can enable this feature, but keep in mind that it will increase build time.

You can enable compiling view by following these steps:

  • Unload project
  • Open project file
  • Find <MvcBuildViews>false</MvcBuildViews> and change it to have true
  • Close project file and reload project

Its really Very Simple Answer Go through this Steps:

Unload Project

Edit Project

Than Search :

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
  <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>

below add

<Target Name="AfterBuild" Condition="'$(Configuration)'!='Debug'">
  <RemoveDir Directories="$(BaseIntermediateOutputPath)" />
</Target>

That's it Than Unload Project . Build

And Check Ur Syntax Is work properly .

I am Sure.