There are many posts on this, most of which suggest adding the MVC project type GUID to the .*proj file.
THe website project model doesn't have a project file though, so is there some way to get support for the add view dialog and tooling with a hybrid website / MVC project?
There is no way to achieve what you want in a WebSite (at least not currently). The Add Controller functionality is implemented as a VSPackage that gets loaded when the MVC project type GUID is detected (that's why all the other posts mention it).
Related
I have an existing website coded in ASP.Net 4.0 Webforms, and would like to add an "ASP.Net Dynamic Data Entities Web Application" (project templates of VS2010 to my actual project):
So my question is, what are the steps to "merge" the 2 projects or integrate the "ASP.Net Dynamic Data Entities Web Application" to my actual webforms.
I think I must merge my Global.asax.cs files and web.config file + move rest of the files. Is that correct ?
I already read that post (that may be outdated?):
http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx
Thanks for your answers :)
(the original title of this post was: “ASP.Net Dynamic Data Entities Web Application” integration with an existing Webforms)
I've read Scott Hanselman's article which you've provided in your question and yes the same technique still applies today, here are a few steps/considerations which should help you along the way:
When you create the new ASP.NET Dynamic Data Entities Web Application make sure that it's the same .NET Framework version as your Web Forms project, to avoid version conflicts.
Remember to add a reference to all the required libraries that you've been using in the Web Forms project.
Now it's safe to copy all the necessary .aspx pages to the new site.
There is some automatically generated code inside the Global.asax of a Dynamic Data project which is used to configure ASP.NET routing, it may be useful later so instead of replacing it with your Global.asax use a tool like WinMerge to merge the two files.
I have an ASP.NET application which works just fine, but which is becoming unwieldy. I would like to incorporate MVC3 functionality in it for any new pages, and gradually convert all the old pages. I plan to use the Razor syntax.
I've got it working. I can serve up pages just fine. It was a bit of a battle, but things looked good. I believe I have all the directory structure and the referenced DLLs.
My only real problems are with the IDE:
I cannot select "Add Controller.." when I right-click on the Controllers folder. Ditto for Views, and "Add Area..." from the project right-click menu.
I cannot add template items related to MVC3 (or MVC2, which I also have installed).
I also cannot validate HTML5 (all tags are invalid), but I think this is a separate issue, because this functionality doesn't work on my MVC3 projects either.
I would not even know that these things were missing if it didn't work perfectly for a project created as an MVC3 project (with Razor syntax), so it must be something specific in the solution or the project, but I cannot find it anywhere.
My question:
Where do I change this so that the IDE acknowledges it as an MVC project?
The reason why the menus are not coming is visual studio IDE do not consider this as a real ASP.NET MVC project because the project file does not say so. So we should update the project file to include the project type guid for ASP.NET MVC and then the IDE willl start supporting the menus specific for ASP.NET MVC type project.
Step 1
Go to your solution explorer and unload the existing ASP.NET project by right clicking and selecting “Unload Project”
Step 2
Right Click the Project in solution explorer and select “Edit your project file name“
Step 3
Add the below entry to it inside the ProjectTypeGuids section
{E53F8FEA-EAE0-44A6-8774-FFD645390401};
Save. Reload the Project and you will be good now.
I clearly explained it here in a blog post.
I have an existing solution in VS2010. When I click the properties of my project I get the view as can be seen in image1.png:
When I create a new empty ASP.NET web application and click the properties of my project I get the view as can be seen in image2.png:
A huge difference.
Now I'm implementing this code here: http://wcf.codeplex.com/wikipage?title=Getting%20started:%20Building%20a%20simple%20web%20api
And that tutorial assumes I get a view as I've shown you in image2.png
In image1 and image2 I've also marked the menu items: "Website" and "Project"
This makes me assume that I've created a website application whereas I need something different (I'm thinking a web application project).
Not sure what to do now, I need to convert my current application to another thing, but to which type and how to do it?
I also came accoss this post: http://blogs.msdn.com/b/webdevtools/archive/2009/10/29/converting-a-web-site-project-to-a-web-application-project.aspx
But before I start screwing up everything :P Is that what would solve my problem?
It should be possible to use either a web site or a web application project. In the example on the link you've posted, they use the predefined template for ASP.Net MVC Web Applications. This has several advantages - it sets up the structure and other resources for you - it's effectively a template.
For the purposes of the tutorial, why don't you just set up an application that way? If you've already written some code, you can just import it into the new application.
For future projects, you might want to consider which is best for your needs. Apart from structure, there are some other key differences between a web application and a web site project.
MSDN handily provides the differences here:
http://msdn.microsoft.com/en-us/library/dd547590.aspx
If you find you want the features of the web application, then the link you've posted is fine. You'll need to do some re-organizing of your references and so on and so forth, but the process is fairly straightforward (but not painless).
A "web site" in visual studio is the old, .net 1 style of creating web sites. It basically dynamically compiles the code in a folder when it's hit for the first time. Later .NET introduced a "web application" model where the code is compiled into a DLL and no code files are deployed with the site. "Web sites" are pretty much depcrated and shouldn't be used for any new projects unless you're doing a quick demo site.
The codeplex project you referenced also depends on MVC 3 (which are web applications).
You are probably better off just restarting like the tutorial says - create a new MVC application like it shows in its first screenshot.
If you do not have that option, use Web Platform Installer to add MVC for you - http://www.microsoft.com/web/downloads/platform.aspx
Good luck!
I can't tell exactly what's going on from your screenshots, but if you have a web site that you need to convert to a web application project, you can find the directions here
Although the instructions are specific to VS2005, they are basically the same for 2010 as well.
I happend to go through the below site from one of the Stack over flow Questions.
http://webclientguidance.codeplex.com/wikipage?title=Getting_Started_Feb_2008
Is this "One of the" way to create our web app from VS?
I can create a Website,Web App,MVC web apps. now one more? man, its getting confusing.
I have interpreted the question as being related to project templates and the process of starting a new project in Visual Studio.
Visual Studio allows anyone to create a project template. It comes loaded with things like "Windows Forms Application" and "Web Application" and you can load other templates that suit your needs, such as the "ASP.NET MVC Website" template, or the template you note above.
The idea of the template is that it lays out all of the boilerplate stuff that you are likely to use in a particular scenario. For example, if you write an application that has a plugin architecture, you might create a project template for a plugin, which has the code all laid out ready to be implemented, so each time you write a plugin, you start writing code straight away - rather than spending time laying out the structure of the plugin.
So don't be confused by new templates. Choose the templates that suit what you need to do and stick to those!
Creating a "Website" in Visual Studio uses ASP.Net WebForms, using a method that means the pages are compiled on-the-fly - there's no DLLs created. This method is not really encouraged, and is no longer the default in Visual Studio 2010.
Creating a "Web App" in Visual Studio also uses ASP.Net WebForms, but compiles the site, so the code-behind and any class files are compiled into a DLL.
MVC is an alternative framework to WebForms that also uses ASP.Net.
As for the Web Client Software Factory, this is a toolkit to help you create a Web App project in a "patterns and practices" way. I've only just looked at the site, but it seems to be using WebForms as opposed to MVC.
So there's essentially a choice between WebForms and MVC in terms of ASP.Net frameworks, but after making that choice, there's several other sub-paths you can go down.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
ASP.NET MVC alongside Web Forms in the same web app?
I am kinda new to .NET applications, I have a web forms application that I am working on and I am about to start the development of new pages, I am trying to make the new pages with the ASP.NET MVC, but I am not beeing able to make the pages hit the controllers. First i added the library references added the routes on the global.asax but not sure what else is missing, can someone help me out?
thx.
Reading between the lines I gather you are trying to add MVC pages to your existing ASP.NET Webforms Webapplication?
If that is the case then you probably need some MVC specific config. settings. Easiest way is to create a new MVC web app and then merge the config settings.
Furthermore if you are doing a hybrid project I'd recommend giving Scott Hanselmann's post on the topic a read.
There's a more step-by-step description of adding MVC to a WebForms Application at these links:
Integrating ASP.Net MVC Into An Existing ASP.Net Web Application
Mixing ASP.NET Webforms and ASP.NET MVC
You might also want to add the ProjectTypeGuid to the project file with a text editor ({603c0e0b-db56-11dc-be95-000d561079b0} is used to designate to Visual Studio to use the MVC extensions.)
<ProjectTypeGuids>{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
The links above also don't fully cover the system.webserver area of web.config that needs to be configured.
Scott Hanselman released a "totally unsupported" Nuget package that adds MVC 3 features to an existing Web Forms project. It also works on my PC (ha ha) and I've used it on several projects.
http://nuget.org/List/Packages/AddMvc3ToWebForms
He blogged about it here:
http://www.hanselman.com/blog/CreatingANuGetPackageIn7EasyStepsPlusUsingNuGetToIntegrateASPNETMVC3IntoExistingWebFormsApplications.aspx
One newb tip: this package will configure your MVC routes in /App_Start/RegisterMvc3Routes.cs
I've spent a lot of time over the past few months on this. Here are my observations.
The good/easy
- Getting Webforms to call into MVC controllers
- It was remarkably easy to stand up a new MVC3 project and drop Webforms pages into it.
- I was able to move my <pages><controls></controls></pages> section into the /pages directory in a new web.config there
The dirty/difficult
Regarding the GUID
Please note that the GUID has to be added at the front of the line for some reason... everytime I tried it failed. Until I stumbled on a post that insisted it be the before the others.
also I don't know what the difference is but I have a different GUID working... {E53F8FEA-EAE0-44A6-8774-FFD645390401}
getting the landing page to be Webforms caused ALL kinds of snags.
getting jQuery intellisense to play nicely with T4MVC
this is what I did to address that
#if (System.Diagnostics.Debugger.IsAttached)
{
<script src="../../Scripts/Mvc3/jquery-1.7-vsdoc.js" type="text/javascript"></script> #* intellisense! *#
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_js)
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_js)
}
else
{
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_1_7_min_js)
#Html.RelativeJavascript(Links.Scripts.Mvc3.jquery_unobtrusive_ajax_min_js)
}
Recommendations:
Use T4MVC in ALL cases even if you are pure webforms. The elimination of magic strings for static content (.js,.css, images, specifying templates) is outstanding.
and if you have any part of your build process compiling views then you get compile-time safety on any of those links.