Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up project of htmlHelpers so that it produces two dlls - for mvc3 and mvc4?

I have a library of html helpers as a separate project. Right now it references system.web.mvc of version 4.

If I try to use this library in a project that uses mvc3 it throws an error when a helper is attempted to be used:

Compiler Error Message: CS1705: Assembly 'MyHtmlHelpers, Version=3.7.4.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

I understand that I need to build my helpers project with system.web.mvc of version 3 referenced in order for it to be compatible with mvc3 project. I do not want to have two projects with the same code with just the difference of system.web.mvc referenced.

Question is in the title. Any help is appreciated.

like image 512
Dmitry Efimenko Avatar asked Oct 20 '22 20:10

Dmitry Efimenko


1 Answers

I do not want to have two projects with the same code with just the difference of system.web.mvc referenced.

You don't necessarily need to physically duplicate the source code. You could just have another .csproj for your class library which will add the source code as Linked Files and only replace the version of the System.Web.Mvc reference in the .csproj.

Take a look at how standard projects such as JSON.NET have their source code organized. They support multiple versions of .NET from 2.0 up to 4.0 and yet the source code is the same. It's the project files that are doing the job.

like image 138
Darin Dimitrov Avatar answered Nov 01 '22 13:11

Darin Dimitrov