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

查看:125
本文介绍了如何强制应用程序使用.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.

然而,当LINQ的访问,因为它看起来在.NET 3.5库。其中两个。NET 2(或3.0)和.NET 4的安装,应用程序加载与.NET 2台,和崩溃

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版本,也就是2的情况下,.NET 3.5。

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

(请注意,类似的问题是没有答案的元素的文档<的社区内容部分/一>)

(Note that similar question is left unanswered in the Community Content section of the Element documentation)

推荐答案

成型的问题导致我的答案。正如元素文档

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

在多个版本的运行时   支持,第一元件   应指定最preferred   版本的运行时的,最后   元素应指定至少   preferred版本。

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,和CLR 2是未安装CLR 4)实现了第二个选项是扭转的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天全站免登陆