Click here to Skip to main content
15,867,849 members
Articles / All Topics
Technical Blog

Upgrading S#arp to MVC4

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
5 Oct 2013CPOL2 min read 7.6K   4   1
How to upgrade S#arp to MVC4

First of all, I can assure you that S#arp will work on MVC4 and I am using Sharp Architecture 2.0.4. We just recently migrated and tested 2 large S#arp projects and it is fully working and is running in production.

Now let's go to the details, I guess you came across this article either because you want to use MVC4 with your S#arp project or you got this “Entry point was not found” error because you recently installed MVC4 on your machine.

1 Entry point was not found

If it's the second reason yes, it is MVC4 doing it and not S#arp your project just auto referenced the latest MVC version. Now to fix that issue, you need to upgrade your S#arp project to use MVC4 this can also be used in any .NET web projects that is using MVC3 so this guide is not specific to S#arp projects. Let's start!

  1. Go to all of your web projects in this case if it's S#arp it's in the presentation layer. You need to replace all instances of:
    C#
    System.Web.Mvc, Version="3.0.0.0"
    System.Web.WebPages="", Version="1.0.0.0"
    System.Web.Helpers="", Version="1.0.0.0"
    System.Web.WebPages.Razor="", Version="1.0.0.0"

    with:

    C#
    System.Web.Mvc="", Version="4.0.0.0"
    System.Web.WebPages="", Version="2.0.0.0"
    System.Web.Helpers="", Version="2.0.0.0"
    System.Web.WebPages.Razor="", Version="2.0.0.0"

    You can see this in 3 different locations.

    First is in the configSections which means your old web.config lines which looks like this:

    9 Old Config Section

    will become like this:

    10 New Config Section

  2. Next is in system.web.webPages.razor section under host and in system.web under assemblieswhich means your old web.config lines which look like this:

    2 Old config

    will become like this:

    3 New config

    Finally, check also under the views folder, there is one web.config file in there.

    11 Other Web Config

    Old one will be like this:

    12 Other Web Config OLD

    Change it so it looks like this:

    13 Other Web Config NEW

    In the root Web.config file, update or add the following is not yet there:

    XML
    <appSettings>
      <add key="webpages:Version" value="2.0.0.0" />
      <add key="PreserveLoginUrl" value="true" />
    </appSettings>
  3. In Solution Explorer, right-click the project name (if using s#arp it's the {ProjectName}.Web.Mvc) and then select Unload Project. This will unload your project and you can edit what’s in the code behind. Once unloaded, right-click the name again and select Edit {ProjectName}.csproj.

    Find the ProjectTypeGuids element and replace {E53F8FEA-EAE0-44A6-8774-FFD645390401} with {E3E379DF-F4C6-4180-9B81-6769533ABE47}.

    So from this:

    6 Replace GUID

    will become like this:

    7 Replace GUID

    Save and close file you just edited, right-click the project, and then select Reload Project. This will load the project with the new settings.

  4. If the project references any third-party libraries that are compiled using older versions of MVC (definitely S#arp is), then you have to add the following three bindingRedirect elements under the configuration section in your web.config:

    Here is what you need to add:

    XML
    <dependentAssembly>
      <assemblyIdentity name="System.Web.Helpers"
            publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Web.Mvc"
            publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="4.0.0.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Web.WebPages"
            publicKeyToken="31bf3856ad364e35" />
      <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
    </dependentAssembly>

So it should look like this:

8 Add assembly Binding


Filed under: CodeProject, Configuration, Programming Tagged: ASP.Net MVC, C#, S#arp Architecture
This article was originally posted at http://macaalay.com/2012/12/12/upgrading-sarp-to-mvc4

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
New Zealand New Zealand
http://nz.linkedin.com/in/macaalay
http://macaalay.com/

Comments and Discussions

 
QuestionNice article Pin
ngo.long27-Nov-14 21:19
ngo.long27-Nov-14 21:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.