Migrating ASP.NET MVC 1.0 applications to ASP.NET MVC 2

NOTE: There is an updated version of this tool that is compatible with ASP.NET MVC 2 RTM.

To help our customers adopt ASP.NET MVC 2 I built an application that helps upgrade Visual Studio 2008 solutions that use ASP.NET MVC 1.0 to use ASP.NET MVC 2 Preview 2. This application is inspired by Scott Hanselman’s blog post on updating ASP.NET MVC projects to work in Visual Studio 2010 Beta 1.

image

Download

The app is a single executable: Download MvcAppConverter.zip (220 KB).

Usage

The only requirement for this tool is that you have .NET Framework 3.5 SP1 on the machine. You do not need to have Visual Studio or ASP.NET MVC installed (unless you want to open your project!). Even though the tool performs an automatic backup of your solution it is recommended that you perform a manual backup of the solution as well.

  • To convert an ASP.NET MVC 1.0 project built with Visual Studio 2008 to an ASP.NET MVC 2 project in Visual Studio 2008 perform these steps:
    • Launch the converter
    • Select the solution
    • Click the “Convert” button
  • To convert an ASP.NET MVC 1.0 project built with Visual Studio 2008 to an ASP.NET MVC 2 project in Visual Studio 2010:
    • Perform the above steps, then open the project in Visual Studio 2010 and it will perform the remaining conversion steps

What it can do

  • Open up ASP.NET MVC 1.0 projects from Visual Studio 2008 (no other versions of ASP.NET MVC or Visual Studio are supported)
  • Create a full backup of your solution’s folder
  • For every VB or C# project that has a reference to System.Web.Mvc.dll it will (this includes ASP.NET MVC web application projects as well as ASP.NET MVC test projects):
    • Update references to ASP.NET MVC 2
    • Add a reference to System.ComponentModel.DataAnnotations 3.5 (if not already present)
  • For every VB or C# ASP.NET MVC Web Application it will:
    • Change the project type to an ASP.NET MVC 2 project
    • Update the root ~/web.config references to ASP.NET MVC 2
    • Update the root ~/web.config to have a binding redirect from ASP.NET MVC 1.0 to ASP.NET MVC 2
    • Update the ~/Views/web.config references to ASP.NET MVC 2
    • Add or update the JavaScript files (add jQuery, add jQuery.Validate, add Microsoft AJAX, add/update Microsoft MVC AJAX, add Microsoft MVC Validation adapter)
  • Unknown project types or project types that have nothing to do with ASP.NET MVC will not be updated

What it can’t do

  • It cannot convert projects directly to Visual Studio 2010 or to .NET Framework 4.
  • It can have issues if your solution contains projects that are not located under the solution directory.
  • If you are using a source control system it might have problems overwriting files. It is recommended that before converting you check out all files from the source control system.
  • It cannot change code in the application that might need to be changed due to breaking changes between ASP.NET MVC 1.0 and ASP.NET MVC 2. Consult the readme for information on breaking changes.

Feedback, Please!

If you need to convert a project to ASP.NET MVC 2 please try out this application and hopefully you’re good to go. If you spot any bugs or features that don’t work leave a comment here and I will try to address these issues in an updated release.

28 Comments

  • Since Preview 2 is, as it implies, is a preview, I guess we'll continue to stick to using ASP.NET MVC 1 for production sites and purely use the converter to play around with ASP.NET MVC Preview 2 for the time being until a RC/RTM is out?

    Nice work, looks like a handy tool!

  • I tried a to do the migration (a large site from MVC 1.0 to 2.0 and from VS 2008 to VS 2010) myself, with disastrous results. I figured I was looking at spending a couple days fiddling with settings to get everything working again.

    Your tool had it up and running in 5 minutes. No issues that I have found so far. Thank you so much!





  • Any chance on getting source code. This doesn't work as is for me. Its failing when looking for specific javascript files...I'm not crazy enough to use the default MVC structure, or leave in all the gunk js the default project uses.

  • Does this converter rely on project type guids? Reason I ask is because all of my MVC Projects do not contain the MVC project type guid (so users can download them from my blog after a presentation and not have to have MVC installed - I include the binaries in my d/l's).

    Thanks!

    Donn

  • I get this error
    Converting between two versions of Visual Studio is not supported

  • where can i find or is there a tool to generate standard CRUD method with LINQ TO SQL?
    I dont want to reinvented the wheel!

    Thanks..

  • Great tool, thanks so much!

  • Can you provide source code for this tool? The tool doesn't work for our MVC v1 project because we have a spcialized folder structure (and the tool can't find some files).

  • Beautiful. Thanks much. And for those using Castle IoC, this signature has changed:
    protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)

  • Event after using the tool, I am not able to open the project. Visual Studio says "The project type is not supported by this installation".

  • This worked quite well for me on a project that was started from the CodeBetter Canvas project.

    Although, it did fail until I added a "Scripts" folder in the "Web" project - so that it could add all of the JavaScript files to it.

  • Worked great for me! Thank you

  • Karl
    >>>>>>>>>> Any chance on getting source code. This doesn't work as is for me. Its failing when looking for specific javascript files...I'm not crazy enough to use the default MVC structure, or leave in all the gunk js the default project uses.

    I am fixing this bug in the tool and will re-release it with support for ASP.NET MVC 2 Beta. I will see if I can get the source code published as well. We do plan to integrate most of this functionality into Visual Studio 2010 as well.

    Thanks,
    Eilon

  • Donn Felker
    >>>>>>>>>> Does this converter rely on project type guids? Reason I ask is because all of my MVC Projects do not contain the MVC project type guid (so users can download them from my blog after a presentation and not have to have MVC installed - I include the binaries in my d/l's).

    Hi Donn,
    The converter relies on the project type GUID for certain parts of the functionality. Some features require that you use the MVC project type GUID, such as to decide whether to add the updated JavaScript files. Other features check whether the project is any kind of class library in order to update references of System.Web.Mvc.dll from 1.0.0.0 to 2.0.0.0. This is to support the scenario where you have a class library project that contains helpers or controllers that you want to convert.

    A workaround is to temporarily add the project type GUID (which should be {603c0e0b-db56-11dc-be95-000d561079b0}), run the converter, and then remove the GUID (which will then be {f85e285d-a4e0-4152-9332-ab1d724d3325}).

    Thanks,
    Eilon

  • sorin
    >>>>>>>> I get this error
    >>>>>>>> Converting between two versions of Visual Studio is not supported

    Hi sorin,
    That error can occur if you try to convert a project that was build with Visual Studio 2010. Right now this tool only supports projects built with Visual Studio 2008.

    Thanks,
    Eilon

  • Your tool works well but you should set the reference to System.Web.Mvc to copy local= true. You need this if you want to deploy a mvc 2 project to Azure.

  • Worked great for me! Thanks!

  • Worked like a charm, awesome!!

  • Worked like a charm! Getting ready to head to MIX10 and I had done ND in VS 2008/MVC and then today I downloaded MVC2 and my solution wouldn't open. Downloaded the converter, ran it on the solution, and I'm good to go. Thank you so much!

  • Upgrade to MVC 2.0 with care if you're using the AntiForgeryToken... you'll kick all your visitors off the site.

    http://weblogs.asp.net/james_crowley/archive/2010/03/18/beware-upgrade-to-asp-net-mvc-2-0-with-care-if-you-use-antiforgerytoken.aspx

  • I upgrade to mvc 2.0 but i couldn't do work the next line from some script

    userName: {
    required: true,
    minlength: 5,
    remote: ''
    },


    I used this line to verified the user name but i can't use the validator beacose when when i put this code the submit button not generate the post, I'm working with json,jquery and mvc2
    Any idea?

  • Jose

    >>>>>>>> I upgrade to mvc 2.0 but i couldn't do work the next line from some script

    If looks like you're trying to do a remote validator. It's hard to tell exactly where the problem is from just that code. If you want a complete sample of how to do a remote validator you can check out Brad Wilson's blog (he's a developer on the ASP.NET MVC team):
    http://bradwilson.typepad.com/blog/2010/01/remote-validation-with-aspnet-mvc-2.html

    Thanks,
    Eilon

  • Saved a lot of time. Thanks!

  • your tool rocks!!!

    fixed my problem instantly!

    great thanks!

  • I get the following error:

    csproj has an unknown type and will not be converted.

    the reason i'm using this is because visual studio 2010 gives me conversion errors about csproj, on every project i have from visual studio 2008.

  • @frenzy

    Can you show me what the error is during the Visual Studio conversion?

    If you can send me a simplified version of your project that has the conversion problem to "elipton -AT- microsoft.com" I can investigate what the problem is.

    Thanks,
    Eilon

  • Hi,

    Its nice share. I have successfully converted my application from MVC 1 to MVC 2.

    Jatin Kacha - Dhanashree Inc

    B.Sc(IT), MCTS
    .Net & SQL Server Tech. Leader

    Blog : http://jatinkacha.wordpress.com/
    LinkedIn : http://in.linkedin.com/in/jatinkacha
    Company: http://www.dhanashree.com


  • Once i upgrade to MVC 2.0 UNABLE TO CREATE VIEW. And also right+click on the folder select new item, from the Web option can not see mvc.

    If having any solution for these issues please update.

Comments have been disabled for this content.