Pages

Sunday, May 22, 2011

MVC Visual Studio Helpers

If you mix Web Forms and MVC in the same project, Visual Studio helpers for MVC come in really handy when adding Controllers, Views, and so on. It is as easy as right-clicking the Controllers directory and the Add menu will display "Controller" at the top of the list. This is really convenient. Depending on the context, the destination of the right-click, different options will be displayed in the Add menu.

However, if you are modifying an existing Web Forms project to work with MVC, these options will not be available by default. The fix is simple.

In your existing Web Forms project's .csproj file, locate line

    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

and add one more guid at the front, so that it looks like this:

    <ProjectTypeGuids>{E53F8FEA-EAE0-44A6-8774-FFD645390401};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

Now all the options available at the MVC project will be available in the (previously) Web Forms Application project.

 

No comments: