我有一个 html 助手库作为一个单独的项目。现在它引用版本 4 的 system.web.mvc
。
如果我尝试在使用 mvc3 的项目中使用此库,则在尝试使用助手时会抛出错误:
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'
我知道我需要使用引用的版本 3 的 system.web.mvc
构建我的助手项目,以便它与 mvc3 项目兼容。我不想让两个项目的代码相同,只是引用的 system.web.mvc
不同。
问题在标题中。 感谢您的帮助。
最佳答案
I do not want to have two projects with the same code with just the difference of system.web.mvc referenced.
您不一定需要物理复制源代码。您可以为您的类库添加另一个 .csproj,它将源代码添加为链接文件,并且仅替换 .csproj 中 System.Web.Mvc 引用的版本。
看看 JSON.NET
等标准项目是如何工作的组织他们的源代码。它们支持从 2.0 到 4.0 的多个 .NET 版本,但源代码是相同的。是项目文件在做这项工作。
关于c# - 如何设置 htmlHelpers 项目,以便它为 mvc3 和 mvc4 生成两个 dll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20188504/