Mixing MVC and Webforms - Displaying BOTH Context Menus - asp.net-mvc

I have added MVC4 to an ASP.NET Webforms project in Visual Studio 2010.
I changed the .csproj's project type to that of an MVC4 project as detailed here:
Context menu to Add Controller/View missing
to give me the MVC specific context menus.
Now the ASP.NET Webforms context menus (such as add 'UserControl') are gone.
How can I hack VS2010 to give me both the MVC4 and ASP.NET context menus for a given project?

In short and officially: no, this is not possible (disclaimer: I'm a software engineer at Microsoft who used to work on Visual Studio + Blend, but now Internet Explorer).
In Visual Studio, a project only has a single type, and the "ASP.NET Web Application" (WebForms) and "ASP.NET MVC Application" (ASP.NET MVC) are two different project types - they're very similar and share common features, but are still different types.
The MVC project type does not have UserControls and other Items in the Add New Item dialog or context-menus because they're largely irrelevant and wouldn't work as you expect them to (granted, it is possible to have WebForms (and not just using .aspx files as Views)) but I don't think it's a good application-design decision.
Unofficially... the items that appear in the Add New Item dialog are specified in the registry. This is documented here: https://msdn.microsoft.com/en-us/library/bb165141.aspx however this information is intended for developers of new project types, rather than allowing users to modify their own (and certainly you're at risk of breaking your VS if we release another update which makes assumptions about how your Add New Item templates are configured).
If you want to do it this way - go ahead, but be careful, and make a note of everything you do so you can undo it.

Since the IDE is based on working in single mode, It seems we have 2 ways:
Attempt to use a configuration that is done an OR action between two project types, so we have both of them, but lack of true functionality is demanded :(
Write some lines of C++ code to change configuration immediately (based on tip here), so you have a switcher application to run when you want :)

Related

Visual Studio Update 2015, many options for ASP.NET MVC project missing

I just installed Visual Studio 2015 Update 1, and a lot of the configuration I was used to is missing or different. I'd like to know if these changes are due to something simple (like a package I need to install), or if it's something a little more complex.
I'm mainly using Visual Studio to create MVC apps from scratch, so before the update, I would create an empty MVC app with the "Add core references and folders for MVC" selected. Now, I can only create an empty MVC project with nothing pre-configured, or a fully scaffolded MVC app.
In the empty MVC project, there's no option to "Add Controller" when I right-click the "Controllers" folder I create. However, this option is available in the generated one.
The Add New Item menu is divided into Server-side and Client-side templates for the generated app, but it's divided into Code/Data/General/Web/etc. in the empty app. There's also an option to add an MVC View in the generated app, but there's nothing with Razor for the empty app. No .cshtml intellisense in the empty app, either.
There's a lot of functionality and options missing from the empty app that seem like they have to do with how the app is an MVC app, since they're available for the generated app. Is there a straightforward fix that will allow me to create an MVC app using Razor from an empty template?
Figured it out! I was using the ASP.NET 4.5.2 Empty Template, and choosing the ASP.NET 5 Template solved the problem.

ASP.NET MVC 5 Custom Scaffolding Option [t4 templates]

Currently , I am developing a framework , I want to add custom scaffolding option in visual studio menu.
By default "MVC5 Controller with views, using Entity Framework" option 3 from the dialog box chooses "CodeTemplates\MvcControllerWithContext\Controller.cs.t4" , that t4 again targets view t4 templates inside
"CodeTemplates\MvcView\ModelMetadataFunctions.cs.include.cs.t4"
"CodeTemplates\MvcView\Create.cs.t4"
"CodeTemplates\MvcView\Edit.cs.cs.t4"
"CodeTemplates\MvcView\Delete.cs.cs.t4"
"CodeTemplates\MvcView\List.cs.cs.t4"
I have been modifying t4 templates almost a year, I haven't found a single piece of evidence that suggest that how it is targeting those views or how to add option in the scaffolding dialog. I have googled a lot , however haven't found anything close.
In summary , I am only looking for the place where I can add or modify the locations for those t4 templates and add a reference of a new scaffold in the scaffolding dialog box.
Any of the answer will be dearly appreciated. Thank you.
Before continuing to implement your framework using T4, you should be aware that the ASP.Net vNext team have quietly dropped support for T4 from MVC6 projects, so unless that decision is reversed, you will not be able to upgrade your framework.
As of Visual Studio 2015 CTP6, MVC6 projects do not support Single File Generators, which are a requirement for T4. The reasons given by the ASP.Net vNext team are described on the official GitHub repository for ASP.Net.
https://github.com/aspnet/Home/issues/272
UPDATE
David Fowler from the team has now (29-04-2015) confirmed that Single File Generators will be supported in MVC6, which in turn should allow support for T4.
UPDATE 2
To revert back to your original question on the topic of using Custom Code Templates for Scaffolding, this is not finalised for MVC6 and Visual Studio 2015.
I raised this question on the ASP.Net GitHub issue tracker thread mentioned above; Sayed Ibrahim Hashimi (MSFT) replied there will be some discussion regarding which technology and implementation will be followed, and at the moment the main candidates are T4 or Razor generator.
Sayed pointed to the following article that shows some early thoughts, but stresses that this is not finalised, and people should not time invest in this approach as it is likely to change.
http://blogs.msdn.com/b/webdev/archive/2014/08/23/how-to-customize-scaffolding-templates-for-asp-net-vnext.aspx

change webforms to mvc in visualstudio 2010

i created a blank webforms project instead of an MVC 3 project in visual studio, everything runs fine but i dont have my menues
for example when i right click on the Controllers folder i dont get "Add a controller" option.
does anyone know without starting a new project how to change the type of project into an MVC one so that i get the correct menus.
thanks
It's not that you don't have the menu options, it's that it's a completely different type of [web] application and works in different ways. e.g. Webforms has no concept of controllers so even if you did have a menu option it wouldn't get included in the project as you're expecting.
Because webForms and MVC are so different there could never be a 100% reliable conversion utility.
Just create a new project and copy the files already created. I can't imagine you've written that much code before realising that you're in WebForms, not MVC.
If you have got lots of WebForms code you could always just include this in the MVC project until you can convert it (if necessary) at a later time.
Edit:
If you just want to change the project type you can edit the csproj file of the webforms project and add the following ProjectTypeGuid {F85E285D-A4E0-4152-9332-AB1D724D3325};.
You'll need to update references, files, etc. for this to work but it may be quicker than creating a new project and copying content over. (Especially if you already have the project in source control.)
Note that I've only tested this going from WebForms 4 to MVC2.
Try updating a MVC to ASP.NET Fall Update Release Candidate. There is a link .

Adding asp.net mvc to webforms application - how do I get MVC menu options in VS2010?

I have an ASP.NET WebForms application that I'm adding some ASP.NET MVC to.
I have it working, but how can I get Visual Studio to recognise that it's now an MVC project and give me the context menu options to add a view, etc. inside a controller action method?
Open the .csproj file with your favorite text editor (not Visual Studio) and add the following GUID:
<ProjectTypeGuids>{F85E285D-A4E0-4152-9332-AB1D724D3325};{fae04ec0-301f-11d3-bf4b-00c04f79efbc};{349c5851-65df-11da-9384-00065b846f21}</ProjectTypeGuids>
Notice the {F85E285D-A4E0-4152-9332-AB1D724D3325} GUID. This is what indicates that it is an ASP.NET MVC project.
Once this GUID added to the ProjectTypeGuids node you will get the context menus.
I don't know the specifics, but the easiest way is to create a new MVC project, and then use BeyondCompare (or your comparison tool of choice) on the two project files and see what is missing from your project. Then move those lines over and it should work.
The project file is just an XML file behind the scenes, so doing a text compare is relatively easy.
In VS11 you have to enter this GUID into the ProjectTypeGuids:
{E53F8FEA-EAE0-44A6-8774-FFD645390401}

How do you activate the MVC templates in VS2008 from a WebForms App

I'm in the process of adding ASP.NET MVC to a WebForms app. One of the neat features of an ASP.NET MVC solution that you create from scratch is that a right click on the solution explorer and Add > New Item... will give a list of templates which include the MVC templates. However, in a WebForms app these templates don't appear.
I thought that there might be a setting in the .sln solution file that indicated that one was an ASP.NET MVC app but I couldn't find anything that that stuck out.
EDIT: To expand the question, how does Visual Studio know to add a "Controller..." menu item on to the "Add" menu when you right click on the Controllers folder in the Solution Explorer of an MVC app? Likewise it adds a "View..." menu item to the "Add" menu when you right click on the Views folder. Where does Visual Studio get this info from and how can I add those 2 folders to another web app and get the same functionality?
Ideas?
I believe that the logic for that is contained in the dll
Microsoft.VisualStudio.Web.ExtensionsUI
Which is registered in the Project template used when you create a new ASP.NET MVC project:
<WizardExtension>
<Assembly>
Microsoft.VisualStudio.Web.Extensions,
Version=9.0.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35
</Assembly>
<FullClassName>
Microsoft.VisualStudio.Web.Mvc.TemplateWizard
</FullClassName>
</WizardExtension>
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\CSharp\Web\1033\MvcWebApplicationProjectTemplatev1.cs.zip
You could probably also mess around with the Project Type Guids in your .xxproj file:
<ProjectTypeGuids>
{603c0e0b-db56-11dc-be95-000d561079b0};
{349c5851-65df-11da-9384-00065b846f21};
{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
</ProjectTypeGuids>
Seem to be the default ones for an ASP.NET MVC project, compare those with the ones in your web application, and go from there.
However, in a lot of these circumstances I'd agree with gisresearch: it's often easier to create the more complex project (the MVC one) first, and then move the origininal into it.
Also, there's nothing to stop you having multiple projects hosted in the same web application - pull the common logic from the web application into a shared class library, and then reference that from a clean MVC app, with a slightly different namespace, and then merge the two sites within IIS, drop the dlls into a shared bin folder (or strongly name them and put them in the global assembly cache), share the images/scripts, and away you go - you just need to take care with the Global.asax, which would be common to both.
How about the other way around. Create an asp.net mvc project firstly, and then add your web form code over.
Here is an example of hybrid app by Scott Hanselman.
You may also consider to create one default asp.net mvc application and asp.net web form application, and then do a text compare of two projects to see what is the difference.
Like Zhaph mentioned, adding the ProjectTypeGuid worked for me. Unload the web project, edit, and add in the extra ProjectTypeGuid to the existing list.
{603c0e0b-db56-11dc-be95-000d561079b0};

Resources