强制应用程序在特定的 .NET 运行时版本下运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2046089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Force an application to run under specific .NET runtime version?
提问by noctonura
I have .NET 2.0 runtime installed, then I installed the .NET 4.0 runtime, so I have both. When I run a .NET app, is there a way to force which runtime will be used?
我安装了 .NET 2.0 运行时,然后我安装了 .NET 4.0 运行时,所以我两者都有。当我运行 .NET 应用程序时,有没有办法强制使用哪个运行时?
Edit/Clarification:I meant w/o regards to how the application was built. I am under the assumption that the .NET 4.0 runtime can run a .NET program compiled 5 years ago that targeted the 2.0 runtime (oldprogram.exe). So now I am on a machine with both runtimes, either of which couldhandle oldprogram.exe. Which runtime is chosen? Can I influence which runtime is chosen?
编辑/澄清:我的意思是不考虑应用程序的构建方式。我假设 .NET 4.0 运行时可以运行 5 年前编译的针对 2.0 运行时 (oldprogram.exe) 的 .NET 程序。所以现在我在一台具有两个运行时的机器上,其中任何一个都可以处理 oldprogram.exe。选择哪个运行时?我可以影响选择的运行时吗?
回答by Hans Passant
Yes, use the <supportedRuntime>element in the .exe.config file. For example:
是的,使用<supportedRuntime>.exe.config 文件中的元素。例如:
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
回答by Rubens Farias
Take a look: Configuring Assembly Binding Redirection
看一看:配置程序集绑定重定向
By default, applications use the set of .NET Framework assemblies that shipped with the runtime version used to compile the application. You can use the appliesTo attribute on the
<assemblyBinding>element in an application configuration file to redirect assembly binding references to a specific version of the .NET Framework assemblies. This optional attribute uses a .NET Framework version number to indicate which version it applies to. If no appliesTo attribute is specified, the<assemblyBinding>element applies to all versions of the .NET Framework.
默认情况下,应用程序使用一组 .NET Framework 程序集,这些程序集随用于编译应用程序的运行时版本一起提供。您可以使用
<assemblyBinding>应用程序配置文件中元素的 applyTo 属性将程序集绑定引用重定向到特定版本的 .NET Framework 程序集。此可选属性使用 .NET Framework 版本号来指示它适用于哪个版本。如果未指定 applyTo 属性,则该<assemblyBinding>元素适用于 .NET Framework 的所有版本。
回答by o.k.w
Here's a list of MSDN reference to target specific .NET Framework version for VS.NET projects:
以下是针对 VS.NET 项目的特定 .NET Framework 版本的 MSDN 参考列表:
How to: Target a Specific .NET Framework
Visual Studio 2010
How to: Target a Specific .NET Framework Version or Profile
Visual Studio 2010
如何:针对特定的 .NET Framework 版本或配置文件

