我的项目可以引用针对较低版本的.net框架的程序集吗?

Can my project reference an assembly targeting a lower version of .net framework?
2021-06-20
  •  译文(汉语)
  •  原文(英语)

我在.net平台上的时间还不够长,不到2个月.我有这个"无法从程序集等等加载类型blah.blah.blah.

所以我一直在与几种资源作斗争,包括diff此处的建议.仍然没有运气.但是最接近的建议似乎表明某些参考可能针对的是.net的较低版本.实际上,有许多针对不同版本的引用,并且在某些此类引用中,还有许多可能针对差异版本的从属程序集.

我一直在努力使用VS 2010(.net 4.0)来转换我拥有源代码的某些程序集,而整个东西几乎使我不知所措.

因此,我很无奈地问:我的参考组件(及其依赖项)和我的项目目标必须使用相同的版本吗?

速聊1:
如果您也知道我可以尝试解决原始问题的原因/解决方案,我将很高兴听到.
速聊2:
这篇文章中的语法有很多不足之处.如果您修改解决方案文件以指示要执行此操作,则您的应用程序可以将一个版本作为目标,而将另一个版本作为目标.该标志有据可查.问题的一般性质不允许给出具体的指示. 对.net框架的版本有一定的限制,当然可以将编译后的程序集加载到.net框架的不同版本.
解决过程1

只要库的目标版本是<=您的代码所需的版本,就可以了.请注意,当然,任何行为更改都可能导致细微的错误,但这很少见-从根本上讲应该可以.

如果库的目标是更高版本:不好的事情.

我怀疑有关特定的"无法从程序集等等加载类型blah.blah.blah"的更多上下文.会很有用.

解决过程2

不,没有必要参考组件(及其依赖项)和您的项目目标使用相同的版本.

我认为您遇到另一个问题,因为无法加载项目或程序集.

记住

1>添加所有缺少的程序集

2>不要在2008年或更低版本中运行4.0定位项目(不要在较低版本的SDK中运行较高版本的项目)

I'v not been too long on the .net platform.less than 2months. I'm having this "could not load type blah.blah.blah from assembly blah.

So i'v been battling it with several resources including the suggestions in diff post here.Still no luck. but the closest suggestion seems to indicate that some of references might be targeting a lower version of .net. Actually there are many many references targeting different versions and within some of this references there are many more dependent assemblies that possibly are targeting diff versions.

i'v been struggling to convert some of the assemblies i have the source using VS 2010(.net 4.0) and the whole stuff is almost overwhelming me.

And so i'm asking in frustration: MUST MY REFERENCE ASSEMBLIES(and their dependencies) AND MY PROJECT TARGET the same version?

Talk1:
if you also know a reason/solution i could try for the original issues,i'd be glad to hear it.
Talk2:
The grammar in this post has alot to be desired. You application can target one version and a reference target the other provided you modify the solution file to indicate you want to do this. This flag is well documented. The generic nature of the question does not allow for specific directions to be given. There are limits on versions .net framework can load assemblies compiled to a different version of the .net framework of course.
Solutions1

As long as the libraries target a version that is <= the version your code wants, then that is fine. Note, of course, that any behavior changes could cause subtle bugs, but this is rare - fundamentally it should work ok.

If the libraries target a higher version: bad things.

I suspect more context about the specific "could not load type blah.blah.blah from assembly blah." would be useful.

Solutions2

No it is not necessary REFERENCE ASSEMBLIES(and their dependencies) AND Your PROJECT TARGET the same version.

I think you got another issue for could not load project or assembly.

Keep in mind

1> Add all assembly which is missing

2> don't run 4.0 targeting project in 2008 or lower (don't run higher version project in lower version SDK)

转载于:https://stackoverflow.com/questions/18530915/can-my-project-reference-an-assembly-targeting-a-lower-version-of-net-framework

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入