Upgrading S#arp to MVC4





5.00/5 (2 votes)
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.
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!
- 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:
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:
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:will become like this:
- Next is in
system.web.webPages.razor
section underhost
and insystem.web
underassemblies
which means your old web.config lines which look like this:will become like this:
Finally, check also under the views folder, there is one web.config file in there.
Old one will be like this:
Change it so it looks like this:
In the root Web.config file, update or add the following is not yet there:
<appSettings> <add key="webpages:Version" value="2.0.0.0" /> <add key="PreserveLoginUrl" value="true" /> </appSettings>
- 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:
will become like this:
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.
- 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 theconfiguration
section in your web.config:Here is what you need to add:
<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:
Filed under: CodeProject, Configuration, Programming Tagged: ASP.Net MVC, C#, S#arp Architecture
