4

When working on a c# MVC3 app in Visual Studio 2010, I have turned on view compilation by editing my project file and setting the wonderful flag

`<MvcBuildViews>false</MvcBuildViews>`

to true. I love it as it means I can compile my views and catch errors.

The only problem that I have now is that it's not really quick! (I have tried turning it off and then it's back up to full speed.)

It looks like it recompiles every view every time - I have about 50 views at the moment, so ideally it would only compile the pages that have changed since last time. Is this at all possible?

2 Answers 2

2

I don't think its possible to compile that way in the same project. You could attempt to pull out the views into a separate project, and set it up that way.

http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll/

Sign up to request clarification or add additional context in comments.

3 Comments

It's a nice idea, but I don't think it's going to help, it'll still be slow when compiling all of those views in that project.
It will.... but the hope is they will precompile only once since the referenced project hasn't changed. May be worth a shot to see if it works in that scenario
That's a good point, because if I were to change code in a controller it wouldnt recompile the views. Nice one :)
2

As far as I know, building the views is an all-or-nothing flag.

I recommend turning this option off for development environments, but turning it on for a continuous build system that's pointing at your main development branch. That way you can still get an email if you commit something that breaks a view, without adding a lot of time to each build during development.

5 Comments

I'd actually recommend the opposite. Others on the team may update before the build is finished and now they can't compile on their local workstation. I'd rather my team know the code they are committing won't break the build instead of hoping they won't.
@Andy that defeats the whole point. StriplingWarrior that's a good idea - I hadn't thought of that :)
@LachlanB My comment doesn't solve your problem, but my point is that maybe there are other factors to consider. If its just you, go for it, it doesn't matter if you break the build. But on larger teams, checking in code that doesn't compile can bring a good chunk of the teams productivity now. If you're displined you can keep it off until you go to commmit and do a pre-commit compile. That would solve both problems, but I've found people forget and end up committing the change that keeps view compiling off.
@Andy: Thanks for your input. There's obviously no single workflow that's the best for every team. Ideally each member would do a full compile and run all unit tests before committing, but in my experience adding half a minute to every build during development slows down production a lot more than an occasional broken build, provided the broken build emails all the team members immediately. Using a modern DVCS, it's pretty easy to move back to a non-breaking changeset or even "back out" the offending changeset while the committer figures out what they needed to do differently.
You both raise good points, thanks muchly for your thoughts. I'll ponder this over the next couple of days. I wonder if it has been improved in mvc4?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.