如何强制应用程序使用 .NET 3.5 或更高版本? [英] How to force an application to use .NET 3.5 or above?

查看:25
本文介绍了如何强制应用程序使用 .NET 3.5 或更高版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序是使用 VS 2008 构建的,使用 Linq 并将目标框架设置为 .NET Framework3.5.

Our application is built with VS 2008, uses Linq and has Target Framework set to .NET Framework3.5.

当机器上只安装了 .NET 3.5 或 4 时它工作正常.

It works OK when only .NET 3.5 or 4 is installed on the machine.

但是,在安装了 .NET 2(或 3.0)和 .NET 4 的机器上,应用程序加载了 .NET 2,并在访问 Linq 时崩溃,因为它会查找 .NET 3.5 库.

However, on machines where both .NET 2 (or 3.0) and .NET 4 are installed, the application is loaded with .NET 2, and crashes when Linq is accessed, as it looks for the .NET 3.5 libraries.

在 app.config 中使用标记似乎没有帮助,因为它指定了 CLR 版本,在 .NET 3.5 的情况下为 2.

Using the tag in app.config doesn't seem to help, as it specifies the CLR version, which is 2 in case of .NET 3.5.

请注意,我们的安装会验证是否安装了 .NET 3.5 或更高版本.

Note that our installation verifies that .NET 3.5 or upper is installed.

有没有办法告诉应用程序加载:

Is there a way to tell the application to load:

  • 它找到的最高 CLR,或
  • CLR 4(如果已安装),CLR 2(如果未安装 CLR 4,或
  • CLR 2(如果已安装 .NET 3.5)和 CLR 4(如果未安装 .NET 3.5)
  • the highest CLR it finds, or
  • CLR 4 if it is installed, and CLR 2 if CLR 4 is not installed, or
  • CLR 2 if .NET 3.5 is installed and CLR 4 if .NET 3.5 is not installed

(请注意,在 社区内容部分中没有回答类似的问题元素文档)

推荐答案

提出问题让我找到了答案.如元素文档中所述,

Forming the question led me to the answer. As mentioned in the Element documentation,

当多个版本的运行时支持,第一个元素应该指定最喜欢的运行时的版本,以及最后一个元素应指定最少首选版本.

When multiple versions of the runtime are supported, the first element should specify the most preferred version of the runtime, and the last element should specify the least preferred version.

所以实现第二个选项(CLR 4 if it is installed, and CLR 2 is CLR 4 is not installed")的实现方式是颠倒app.config中元素的顺序:

So the way to achieve the second option ("CLR 4 if it is installed, and CLR 2 is CLR 4 is not installed") is to reverse the order of the elements in app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0"/>
        <supportedRuntime version="v2.0.50727"/>
    </startup>
</configuration>

这样,如果安装了.NET 4,就会加载它,如果没有,就会加载较早的版本.

This way, .NET 4 will be loaded if it is installed, and an earlier version will be loaded if not.

这篇关于如何强制应用程序使用 .NET 3.5 或更高版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆