thomaswr
thomaswr

Reputation: 525

Reuse shared project for MVC3 and MVC4 Solutions

we have web applications using MVC3 which all share a library with HtmlHelper Extensions.

Is there a way, to make this shared library which has to reference MVC Assemblies also work with MVC4 Applications without converting the one's existing and without duplicating the shared library?

I Tried setting the MVC references on the shared library to SpecificVersion=false, but then it switches to MVC4 and the MVC3 projects can't use it anymore.

Whenever I try to use MVC3 and MVC4 assemblies side by side, I get an unhandled win32 exception.

Any ideas how to solve this, or is the only way to go either full MVC4 or stay at MVC3? Thanks

Upvotes: 2

Views: 263

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038940

You could use a binding redirect in the web.config of your ASP.NET MVC 4 application:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
</runtime>

Now you could reference the assembly containing your custom helpers (and which in turn depends on ASP.NET MVC 3) in your ASP.NET MVC 4 application.

Upvotes: 1

Related Questions