简体   繁体   English

在仅具有4.0框架的机器上参考2.0库运行.NET 4.0应用程序

[英]Running .NET 4.0 app with reference to 2.0 library on machine with only 4.0 framework

This would be a real pain to try to duplicate, so I'm hoping someone has a quick answer... 尝试复制会是一个真正的痛苦,所以我希望有人能快速回答......

Suppose I have a .NET 4.0 application, with a reference to a .NET 2.0 library (SharpZipLib in this case). 假设我有一个.NET 4.0应用程序,引用了.NET 2.0库(在本例中为SharpZipLib)。 This of course works fine on a normal machine with .NET 2.0 and 4.0 installed. 这当然可以在安装了.NET 2.0和4.0的普通机器上正常工作。

If the server running this application has only .NET 4.0 and not 2.0 (or 3.0/3.5 etc.), what do I need to do to allow the .NET 2.0 library to run properly? 如果运行此应用程序的服务器只有.NET 4.0而不是2.0(或3.0 / 3.5等),那么我需要做些什么才能让.NET 2.0库正常运行?

From what I've read, it looks like I may be able to put in a config setting for supportedRuntime , but I'm not quite understanding what exactly that does. 从我所看到的,看起来我可能能够为supportedRuntime设置配置设置,但我不太明白究竟是什么。

Will a config setting work, or would only .NET 4.0 libraries function in this environment? 配置设置是否有效,或者只有.NET 4.0库在此环境中运行?

(This is a hypothetical environment - I don't plan on ever having my own servers with 4.0 and not 2.0, but if someone is crazy enough to do it, I want to be able to support them). (这是一个假设的环境 - 我不打算永远拥有我自己的服务器4.0而不是2.0,但如果有人疯狂到可以做到这一点,我希望能够支持他们)。

Thanks 谢谢

The CLR can load older assemblies in the .net 4.0 framework. CLR可以在.net 4.0框架中加载较旧的程序集。

Here's a good read: 这是一个很好的阅读:

http://msdn.microsoft.com/en-us/magazine/ee819091.aspx http://msdn.microsoft.com/en-us/magazine/ee819091.aspx

EDIT: updated quote from article. 编辑:文章更新引用。 Particularly notice the bold 特别注意大胆

The .NET Framework 4 runtime—and all future runtimes—will be able to run in-process with one another. .NET Framework 4运行时以及所有未来的运行时将能够在进程中相互运行。 While we did not back-port this functionality to older runtimes (1.0 through 3.5), we did make sure that 4 and beyond will be able to run in-process with any single older runtime. 虽然我们没有将此功能反向移植到较旧的运行时(1.0到3.5),但我们确实确保4及更高版本能够在任何单个较旧的运行时在进程中运行。 In other words, you will be able to load 4, 5 and 2.0 in the same process, but you will not be able to load 1.1 and 2.0 in the same process. 换句话说,您将能够在同一进程中加载​​4,5和2.0,但您将无法在同一进程中加载​​1.1和2.0。 .NET Frameworks 2.0 through 3.5 all run on the 2.0 runtime and so have no conflicts with one another, as shown in Figure 2. .NET Frameworks 2.0到3.5都在2.0运行时运行,因此彼此没有冲突,如图2所示。

From http://neilblackburn.blogspot.com/2009/10/net-framework-40-backward-compatibility.html (and, transitively, http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/08/03/installing-net-framework-v4-0-and-running-net-2-0-3-0-3-5-3-5sp1-applications.aspx ): 来自http://neilblackburn.blogspot.com/2009/10/net-framework-40-backward-compatibility.html (并且,传递上, http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2009/08 /03/installing-net-framework-v4-0-and-running-net-2-0-3-0-3-5-3-5sp1-applications.aspx ):

Now, I knew that you can't just take a 3.5 Service Pack 1 application and run it on the V4.0 CLR. 现在,我知道您不能只使用3.5 Service Pack 1应用程序并在V4.0 CLR上运行它。 It needs a V2.0 CLR or reconfiguring with a <supportedRuntimes/> tag in order to bend the application to run on the V4.0 CLR and that bending might be something that you don't want to do. 它需要V2.0 CLR或使用<supportedRuntimes/>标记进行重新配置,以便使应用程序在V4.0 CLR上运行,并且弯曲可能是您不想做的事情。

From the link in bryanmac's answer ( In-Process Side-by-Side ): 从bryanmac答案中的链接( 进程中并排 ):

This means that if an application is recompiled to run against the .NET Framework 4 runtime and still has dependent assemblies built against .NET 2.0, those dependents will load on the .NET 4 runtime as well. 这意味着如果重新编译应用程序以针对.NET Framework 4运行时运行,并且仍然具有针对.NET 2.0构建的依赖程序集,那么这些依赖项也将加载到.NET 4运行时。

That can mean, however, that there may be bugs due to being run on a different runtime. 但是,这可能意味着由于在不同的运行时上运行可能存在错误。

如果您拥有SharpZipLib的源代码,则可以将其重建为.NET 4.0

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

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