.net 4 向后兼容性
在 .net 4 中开发的 Windows 应用程序引用在 .net 3.5 中开发的程序集是否需要安装 .net 4 和 .net 3.5 才能运行该应用程序?
我怀疑是这样,正如我的观察之一。 此外,这感觉很合乎逻辑,因为两者的执行都需要不同的运行时。
[编辑] 我明白了:)所以,这是 我真正的问题在SO这里已经有一段时间没有得到解答了。如果你们能解决这个问题,我会很高兴!
应用程序的 app.config 已包含以下几行。
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
Will a windows application developed in .net 4 which references an assembly developed in .net 3.5, require both .net 4 and .net 3.5 to be installed for the application to run?
I suspect so, as is one of my observation. Also, it feels logical as both require different runtime for their execution.
[EDIT]
I'm enlightened :) So, here's my real question which has remained unanswered for a while here at SO. Would be glad if you guys can figure out the issue!
The application's app.config already has the following lines.
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定您是否需要安装 3.5。.net 4.0 CLR 能够加载用 .net 2.0 及更高版本编写的程序集,并且自 .net4 和 2.0 程序集以来,它们似乎不太可能运行不同版本的 CLR可以互相调用,无需任何互操作。
我所知道的是,如果您的可执行文件是 .net 4.0 程序集,则在某些情况下您可能需要修改 app.config 才能加载 .net 2.0 程序集。这是因为安全模型从 .net 2.0 中的 CAS 更改为简化的系统 in 4.0
这对我来说似乎进一步表明,在将 .net 2.0 程序集加载到 .net 4.0 进程中时,实际上并未使用 .net 2.0 clr。
(.net 2.0和4.0指的是公共语言运行时版本,2.0、3.0和3.5都使用2.0版本的CLR)
-edit-
根据 此线程,如果进程是 4.0,则不需要 .net 3.5 来加载 3.5 程序集。
-edit2-
以下是修改 app.config 的方法,让 .net 4.0 可执行文件在所有情况下加载 2.0 程序集(例如运行网络驱动器)
Im not sure you need to have 3.5 installed.. The .net 4.0 CLR is able to load assemblies written in .net 2.0 and up, and it seems unlikely that they'd be running diffrent versions of the CLR since .net4 and 2.0 assemblies can call each other without any interop.
What i do know is that if your executable is a .net 4.0 assembly, you might have to modify your app.config for it to load .net 2.0 assemblies in some cases. This is because the security model changed from CAS in .net 2.0 to a simplified system in 4.0
This to me would seem like further indication that the .net 2.0 clr is in fact not used when loading a .net 2.0 assembly into a .net 4.0 process.
(.net 2.0 and 4.0 referes to the common language runtime version, 2.0, 3.0 and 3.5 all use the 2.0 version of the CLR)
-edit-
According to this thread, .net 3.5 should not be needed to load a 3.5 assembly if the process is 4.0.
-edit2-
Here is how you'd modify your app.config to let a .net 4.0 executable load 2.0 assemblies in all scenarios (such as running of a network drive)
不,您不需要安装 .NET 3.5。假设您没有做任何特别时髦的事情,所有程序集都将加载到同一个 CLR 中,因此 .NET 3.5 程序集最终将使用它所使用的所有类的 .NET 4 实现。
正如 aL3891 提到的,随着时间的推移,安全系统发生了一些变化,但如果它是一个不使用 CAS 的“简单”类库,那么无需任何特殊工作就应该没问题。当然,最好在最终安装到客户的机器上之前测试所有这些:)
No, you won't need .NET 3.5 to be installed. Assuming you're doing nothing particularly funky, all assemblies will be loaded into the same CLR, and so the .NET 3.5 assembly will end up using the .NET 4 implementation of all the classes it uses.
As aL3891 mentioned, the security system has changed a little over time, but if it's a "simple" class library which doesn't use CAS, it should be fine without any special work. Of course, it would be best to test all of this before it ends up on a customer's machine :)
更正:我有一个程序集需要安装 .NET 4.0 和 .NET 3.5;但根据研究,这种情况并不典型,而且通常情况并非如此。
就我而言,将上面 aL3891 的答案中的以下代码行添加到我的 app.config 中,消除了我对 .NET 3.5 的依赖。
Correction: I had an assembly that required both .NET 4.0 and .NET 3.5 to be installed; but according to research, this is not typical and normally not the case.
In my case, adding the following lines of code to my app.config from aL3891's answer above removed the dependency on .NET 3.5 for me.