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

2020-02-10 14:45发布

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?

7条回答
该账号已被封号
2楼-- · 2020-02-10 15:03

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>
查看更多
冷血范
3楼-- · 2020-02-10 15:06

For MVC 4:

<ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
查看更多
我欲成王,谁敢阻挡
4楼-- · 2020-02-10 15:12

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.

查看更多
劫难
5楼-- · 2020-02-10 15:19

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)

查看更多
甜甜的少女心
6楼-- · 2020-02-10 15:20

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

查看更多
祖国的老花朵
7楼-- · 2020-02-10 15:23

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... :)

查看更多
登录 后发表回答