Migrating ASP.NET MVC 2 applications to ASP.NET MVC 3 Preview 1

ASP.NET MVC 3 Preview 1 has just been released! More info on ScottGu's blog.

Download ASP.NET MVC 3 Preview 1!

I just finished up a preview of my ASP.NET MVC application conversion tool to support conversions from ASP.NET MVC 2 to ASP.NET MVC 3.

The previous version of the app that converted from ASP.NET MVC 1.0 to ASP.NET MVC 2 is available here.

image

Download

The app is a single executable: Download MvcAppConverter-MVC3Preview1.zip (256 KB).

Usage

The only requirement for this tool is that you have .NET Framework 4 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 your solution as well.

  • To convert an ASP.NET MVC 2 project built with Visual Studio 2010 to an ASP.NET MVC 3 project in Visual Studio 2010 perform these steps:
    • Launch the converter
    • Select the solution
    • Click the “Convert” button
  • To convert an ASP.NET MVC 2 project built with Visual Studio 2008 to an ASP.NET MVC 2 project in Visual Studio 2010:
    • Open the project in Visual Studio 2010 to convert the solution and project file formats from VS2008 to VS2010
    • Upgrade the .NET Framework target version of each project to .NET Framework 4 because ASP.NET MVC 3 is compatible with only .NET Framework 4
    • Launch the converter
    • Select the solution
    • Click the “Convert” button

What it can do

  • Open up ASP.NET MVC 2 projects from Visual Studio 2010 (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
  • For every VB or C# ASP.NET MVC Web Application it will:
    • Change the project type to an ASP.NET MVC 3 project
    • Update the root ~/web.config references to ASP.NET MVC 3
    • Update the root ~/web.config to have a binding redirect from ASP.NET MVC 2 to ASP.NET MVC 3
    • Update the ~/Views/web.config references to ASP.NET MVC 3
  • 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 build with Visual Studio 2008 or with .NET Framework 3.5.
  • 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 2 and ASP.NET MVC 3.
  • The release notes include manual steps to upgrade your application.

Feedback, Please!

If you need to convert a project to ASP.NET MVC 3 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.

Other Resources

There are already a bunch of blog posts, walkthroughs, and even videos on the new preview, so check them out:

Brad Wilson has a four-part post on ASP.NET MVC 3’s new dependency injection support:

21 Comments

  • Successfully converted to MVC 3.
    Though status text is slightly disappointing:)

    "The project was successfully converted
    The solution was successfully converted to ASP.NET MVC 2"

  • Hi Sergey,

    I think I uploaded an old version of the tool by mistake! I changed the ZIP to be the updated version.

    Thanks for the report!

  • Worked fine except for one of the project on my solution, which was targeted to .NET 3.5 so the added reference was not found, since MVC 3 is targeted to .NET 4. Just updated the target framework and worked fine.
    Thanks a lot :)

  • strongly typed views are having issues thinking the Model is of type object getting
    'object' does not contain a definition for ...

    I used the converter but this is busted ... all in web.config looks on the up and up. Anyone else?

  • @Phil

    >>>>>>>> strongly typed views are having issues thinking the Model is of type object getting
    >>>>>>>>
    >>>>>>>> 'object' does not contain a definition for ...
    >>>>>>>>
    >>>>>>>> I used the converter but this is busted ... all in web.config looks on the up and up. Anyone else?

    Are you having issues with strongly-typed views with the WebForm view engine or the Razor view engine? There may have been a bug in the WebForm view engine that we just recently fixed. I think there was also a small bug in the Razor view engine that we also just recently fixed.

    If you can share the file that isn't working we'll take a look.

    Thanks!

  • Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS1061: 'object' does not contain a definition for 'SetDate' and no extension method 'SetDate' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

  • @TRS

    Can you share some more details about the code that you have that is experiencing the compilation error? One possibility is that you have an item that is declared as 'dynamic' (possibly by using a strongly-typed view page that has its model declared as 'dynamic') and you then try to call an extension method on it. Extension methods are supported only by the compiler itself and not by dynamic objects at runtime.

    If that's the case you'll have to either declare the page as the proper strong type (e.g. a "Customer" model type), or case the object to the correct type and then call the extension method.

    Thanks,
    Eilon

  • I followed your instructions. It worked! Thanks!!

  • The MVC 3 Preview 1 ViewTypeParserFilter was unable to handle a partial view declared like this:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

    I recompiled it with a modified source, basically using the MVC 2 RTM source for ViewTypeParserFilter (the only change was using IMvcControlBuilder in ParseComplete), and after that it worked.

  • @CJ

    Is this the same issue as the one reported on the following StackOverflow post?
    http://stackoverflow.com/questions/3516130/upgrade-mvc-2-to-mvc-3-issues-with-views

    If so then we've identified the issue and it will be fixed for the next preview. Sorry for the inconvenience!

    Thanks,
    Eilon

  • @Eilon

    Yes, I believe it's the same bug. No worries, though, after all it's the first preview! :-) As such, it's very stable.

    By the way, how often do you plan on releasing previews? Whenever you feel you have something that is interesting enough and sufficiently stable, or on a more scheduled basis?

  • @CJ

    We generally do previews roughly every 6 - 8 weeks, which gives us a comfortable enough amount of time to get new features, bug fixes, and other improvements in. We have a lot of existing stuff in the pipeline so stay tuned! :)

  • @mike -

    If you're using ASP.NET MVC 3 Beta then you might be running into a bug that wasn't caught in time.

    To work around the bug you'll need to make sure you have these two items in your ~/web.config file:






    This should disable some new features that weren't supposed to be enabled by default in MVC 3. These flags won't be necessary with the next release.

    Thanks,
    Eilon

  • Regarding the issue: 'object' does not contain a definition for ...

    Just add inyour web.config:





  • Nice tool. Is it possible to add an indication as to whether the targetted file is Read-Only?

    Thanks,

    Mike

  • fyi, I have a SQL database in App_Data that caused the backup to barf (file was in use). I elected to "Continue" with the installation but it aborted anyway. The solution was to detach the database so the backup could do its thing. Thanks and looking forward to working the MVC 3!

  • I converted the mvc 2 application with the tool, and I am getting the error, in production server, [Could not load file or assembly 'System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified].

    I have upload the mvc 3 application in a subdomain before upload it in main domain.

    I checked the web config, and nowhere has the version 2.0.0.0.

    I would appreciate any suggestion.

    Thanks

  • SOLUTION

    I change the to

    Thanks

  • Tried to manually do this a few times but could never seem to quite get it. Ran this tool and had my app converted with no problems. Thank-you!!!

  • Any chance of getting the source code? We want to produce a command line tool that just converts lots of web.configs.

  • @Shuval - We'd like to release the source code at some point, but for now feel free to use a tool such as Reflector to extract the code and then reuse it in any way you like.

    The latest version of the binaries is available here: http://aspnet.codeplex.com/releases/view/59008

    Thanks,
    Eilon

Comments have been disabled for this content.