14

I'm using the standard instructions to compile views at design time, by adding this to my vbproj file:

<MvcBuildViews>true</MvcBuildViews>

But it doesn't seem to do anything. I added a compilation error to a vbhtml file and compiled the app. If the file is open in Visual Studio, I get the compilation error whether MvcBuildViews is true or false. If the file is closed, I don't get the error, even on full build, even when MvcBuildViews is true.

This is VS2012, and I've added the MvcBuildViews entry to every single PropertyGroup in my project file, but still no luck.

What am I doing wrong here?

Update: I just upgraded to VS2013 and I still have the problem.

Joshua Frank
  • 13,120
  • 11
  • 46
  • 95
  • possible duplicate of [MVCBuildViews not working correctly](http://stackoverflow.com/questions/4725387/mvcbuildviews-not-working-correctly) – Mike Cheel Apr 16 '14 at 17:18
  • @MikeCheel: No, I read that post, but I am not getting the same error reported in that post (in fact, I'm not getting any error). – Joshua Frank Apr 16 '14 at 17:25
  • Did you try removing the obj\debug and such as in that article? Are you able to show your proj file? – Mike Cheel Apr 16 '14 at 17:36
  • I did delete `obj`, yes. I tried a number of measures from the article, but I think most of them are focused on deleting bogus web.config files, to get rid of the error he was having, but I don't get that error. – Joshua Frank Apr 16 '14 at 17:43
  • 1
    I ws able to reproduce the no warning\ no error like you have. You also need to add the correct post build stuff. See here: http://stackoverflow.com/a/542944/426422 I got it working when I follow the guys steps. – Mike Cheel Apr 16 '14 at 17:54
  • When I added that, the post build threw a bunch of errors that don't actually happen in the IDE, and I *still* don't get an error for the offending razor view. – Joshua Frank Apr 16 '14 at 18:18
  • What I did to get mine working (I did it in 2013 express, mvc 5) was first unload the project and then edit it. I then put my MvcBuildViews property in the section for my debug \ any cpu property group. Then I copied that AfterBuild blurb right after the commented out version at the bottom of the file. Voila. – Mike Cheel Apr 16 '14 at 19:05
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/50827/discussion-between-joshua-frank-and-mike-cheel) – Joshua Frank Apr 17 '14 at 00:45

1 Answers1

1

To be honest I gave up to MvcBuildViews and did a job using RazorGenerator

https://github.com/RazorGenerator/RazorGenerator

  1. Install it from nuget
  2. Install an Razor Generator extension in your Visual Studio. (Tools -> Extensions and Updates -> Online Tab -> Search For Razor Generator and install
  3. Right Click your view -> Click Properties -> Make sure Custom Tool says RazorGenerator

enter image description here

Michael Samteladze
  • 1,310
  • 15
  • 38
  • This is clever. Having to set the Custom Tool on every single view seems tedious though. Any way to automate that or maybe run a job outside of the IDE to do this compilation? – Joshua Frank Mar 13 '19 at 12:29
  • When I usually start project like this, I do it once and then just copy paste views, (it's kinda habit) so don't need to set Properties manually. Unfortunately couldn't find better way to compile views – Michael Samteladze Mar 14 '19 at 07:52