简体   繁体   English

是否可以在面向 4.0 的项目中引用面向 .net 4.5 的程序集?

[英]Is it possible to reference an assembly that targets .net 4.5 in a project that targets 4.0?

I have a MVC 3 application that targets .net 4.0 It has a dozen or so projects also targeting .net 4.0我有一个面向 .net 4.0 的 MVC 3 应用程序它有十几个也面向 .net 4.0 的项目

I have created a new project for the solution targeting .net 4.5 that uses reflection (there are a couple of nice bits of functionality in 4.5 that I want to use).我为使用反射的 .net 4.5 解决方案创建了一个新项目(我想使用 4.5 中的一些不错的功能)。 When I try to compile I get an error saying that the 'type or namespace (new 4.5 proj) could not be found, are you missing a directive or an assembly reference'.当我尝试编译时,我收到一条错误消息,提示“找不到类型或命名空间(新 4.5 项目),您是否缺少指令或程序集引用”。

Is it possible to have a reference to an assembly targeting .net 4.5 in a project that targets 4.0?是否可以在面向 4.0 的项目中引用面向 .net 4.5 的程序集?

Is it possible to have a reference to an assembly targeting .net 4.5 in a project that targets 4.0?是否可以在面向 4.0 的项目中引用面向 .net 4.5 的程序集?

No. It shouldn't be.不,不应该。 There could be some features that are used in .Net 4.5 assembly which are not part of .Net 4.0, In that particular case, it should fail. .Net 4.5 程序集中使用的某些功能可能不是 .Net 4.0 的一部分,在这种特殊情况下,它应该会失败。

我想您可以将您的项目设置为 .net 4.5,但如果您想将其保留为 4.0,请查看此链接可能对您有所帮助

Yes, it is possible.对的,这是可能的。 Just open the .csproj file for the .Net 4.0 assembly giving the assembly load error in a text editor and set this for the .Net 4.5 assembly reference:只需打开 .Net 4.0 程序集的 .csproj 文件,在文本编辑器中给出程序集加载错误,并将其设置为 .Net 4.5 程序集参考:

      <SpecificVersion>True</SpecificVersion>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM