如何在一个应用程序中支持.NET 2.0和.NET 4.0?
这是一个有趣的。我有一个针对 .NET 2.0 构建的小型可执行文件,以确保它可以在各种平台上运行。它是一个单程序集程序,并且仅引用 System.* 命名空间。
当我在安装了 .NET 2.0 的操作系统上运行它时,它运行良好。由于 .NET 4.0 引入了新的运行时,它无法在仅安装 .NET 4.0 的操作系统上运行。因此,我将支持的运行时信息添加到了 app.config 文件中,如下所述 在这里。我添加了两个受支持的运行时:
<supportedRuntime version="2.0.50727" />
<supportedRuntime version="4.0" />
现在,当我在安装了 .NET 2.0 的系统上运行应用程序时,它无法运行:
除了错误消息中请求版本的顺序更改以反映 app.config 的更改之外,定义支持的运行时的顺序没有区别(因此 CLR显然是正确地获取了该信息)。我已经安装了.NET 2.0,它声称我需要安装.NET 2.0!我尝试修复 .NET 2.0 的安装,但没有成功。我已在第二台机器上重现了此行为。
什么可能导致此失败?
Here's an interesting one. I have a small executable that is built against .NET 2.0, to ensure it operates on a wide variety of platforms. It is a one-assembly program and it references only System.* namespaces.
When I run it on an OS with .NET 2.0 installed, it runs fine. It will not run on an OS with only .NET 4.0 installed, because of the new runtime introduced with .NET 4.0. As a result, I added supported runtime information to the app.config file, as described here. I added two supported runtimes:
<supportedRuntime version="2.0.50727" />
<supportedRuntime version="4.0" />
Now when I run the application on a system with .NET 2.0 installed, it fails to run:
It makes no difference in which order the supported runtimes are defined, other than the order of the requested versions in the error message changes to reflect the changes to the app.config (so the CLR is obviously picking up that information properly). I have .NET 2.0 installed, and it is claiming that I need to install .NET 2.0! I have tried repairing the installation of .NET 2.0 with no luck. I have reproduced this behaviour on a second machine.
What could be causing this to fail?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您可能只是错过了
v
:I believe you may just have missed out the
v
: