“Add Controller” / “Add View” in a hybrid MVC/WebF

2020-02-10 14:30发布

问题:

I have an existing WebForms project to which I'm adding MVC pages. I created an MVC project and copied the project type guids.

It works fine, but I can't get Visual Studio to display the "Add Controller" or "Add View" wizards on my controllers and views directories (they're not /Controllers and /Views, they're in /Foo/Controllers and /Foo/Views).

Is it possible to enable the wizards?

回答1:

For MVC 3, ProjectTypeGuids should look like the following:

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

(See Upgrading an ASP.NET MVC 2 Project to ASP.NET MVC 3)



回答2:

To get full designer support for hybrid projects you need to add MVC "project type" to in the project file.

Open your project file and replace ProjectTypeGuids tag with

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

After that you will see new context menus ("Add View", "Add Area", "Add Controller", etc) in your "old" ASP.NET project

Works for both MVC and MVC 2.



回答3:

For MVC 4:

<ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>


回答4:

I've given up on this. Instead, I have some basic Resharper snippets. Too bad this isn't configurable.



回答5:

Here is the guid for MVC3 :

{E53F8FEA-EAE0-44A6-8774-FFD645390401};

unload your project, open csproj file and add the GUID to the begining of tag. no extra spaces nor line breaks, then reload the project. Like this

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


回答6:

Maybe you could enable them, but why bother? Those wizards are available just two clicks away: right click on the folder, click on Add - New item, then select "MVC View Page" or "MVC Controller Page". They are not in the contextual menu, but they are still quite near... :)



回答7:

This issue is resolved. I have a hybrid project and I had the same problem. Could not able to see "Add View/Add Controller" in the context menu. It is now resolved. Please see the following link Context menu to Add Controller/View missing