如何強制應用程序使用.NET 3.5或更高版本?

[英]How to force an application to use .NET 3.5 or above?


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

我們的應用程序是使用VS 2008構建的,使用Linq並將Target Framework設置為.NET Framework3.5。

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

當只在機器上安裝.NET 3.5或4時,它可以正常工作。

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.

但是,在安裝了.NET 2(或3.0)和.NET 4的計算機上,應用程序加載了.NET 2,並在訪問Linq時崩潰,因為它查找.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.

在app.config中使用標記似乎沒有幫助,因為它指定了CLR版本,在.NET 3.5的情況下為2。

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

請注意,我們的安裝會驗證是否已安裝.NET 3.5或更高版本。

Is there a way to tell the application to load:

有沒有辦法告訴應用程序加載:

  • the highest CLR it finds, or
  • 它找到的最高CLR,或

  • CLR 4 if it is installed, and CLR 2 if CLR 4 is not installed, or
  • CLR 4(如果已安裝)和CLR 2(如果未安裝CLR 4)或

  • CLR 2 if .NET 3.5 is installed and CLR 4 if .NET 3.5 is not installed
  • 如果安裝了.NET 3.5,則為CLR 2;如果未安裝.NET 3.5,則為CLR 4

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

(請注意,在Element文檔的Community Content部分中仍未回答類似的問題)

4 个解决方案

#1


14  

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.

當支持多個版本的運行時時,第一個元素應指定最優選的運行時版本,最后一個元素應指定最不喜歡的版本。

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:

因此,實現第二個選項(“如果安裝了CLR 4,CLR 2未安裝CLR 4”)的方法是顛倒app.config中元素的順序:

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

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

這樣,如果安裝了.NET 4,它將被加載,否則將加載早期版本。

#2


0  

Another useful link is this page on MSDN. This shows all of the values required in app.config if you want to just target the client profile or if you require the full profile.

另一個有用的鏈接是MSDN上的這個頁面。如果您只想定位客戶端配置文件或需要完整配置文件,則會顯示app.config中所需的所有值。

#3


0  

The .NET Framework version 3.0 and 3.5 use version 2.0.50727 of the CLR.

.NET Framework 3.0和3.5版使用CLR的2.0.50727版。

#4


-1  

If you have an unmanaged EXE calling a .NET DLL, you need to create a foo.exe.config file as well, containing the above <startup>... block.

如果您有一個非托管EXE調用.NET DLL,您還需要創建一個foo.exe.config文件,其中包含上面的 ...塊。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/10/17/729e7908d8da889541f8db8d40e2b0bd.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com