ASP.NET MVC Custom View Path breaks Visual Studio

2019-05-09 14:11发布

问题:

I've seen a lot of articles on how to change the default paths for an ASP.NET MVC project so you can relocate or rename your Controllers, Models, and Views folders by extending the RazorViewEngine and specifying new path formats.

So far, this works great but the side-effect is that it has broken the Visual Studio shortcuts for "Go to View" or "Add View...".

Any ideas on whether those shortcut options can be customized to know about the new paths I've specified?

Thanks in advance! - Scott

回答1:

The Visual Studio features cannot be extended to support custom paths. However, in the ASP.NET and Web Frameworks 2012.2 update that will soon be released (you can download a preview right now from here), the Add View functionality was updated to be a lot more flexible regarding which folders will have it enabled and which won't. It now supports Add View in any folder that is anywhere under a folder called "Views".

Regarding Go To View, that was not updated because unfortunately there is no way for the VS tooling to be aware of runtime customizations made to the view engine - I agree it would be cool, though!

(BTW my source for this information is that I work on ASP.NET MVC at Microsoft.)