In Visual Studio 2012, C# code inside MVC views does not get compiled in the normal build process. This can lead to runtime bugs... yucky!
Thankfully, you can force Visual Studio to compile your views with a handy property attribute.
This is how I did it:
- Create a new Build Configuration called DebugBuildViews
- Right click my project in Solution Explorer and Unload Project
- Right click my project in Solution Explorer and Edit MyProject.proj
- Navigate to the Property Group for me new DebugBuildViews Build Configuration (shown below)
- Add the following xml: <MvcBuildViews>true</MvcBuildViews>
- Save the project file
- Right click my project in Solution Explorer and Reload Project
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugBuildViews|AnyCPU'">
Now I can switch to this new DebugBuildViews build config when I want views to compile and switch back to my Debug config when I don't.