How to: Configure an App to Support .NET Framework 4 or 4.5

本文介绍如何通过配置文件指定.NET Framework应用程序运行所需的版本,包括针对不同版本的.NET Framework进行配置的方法及注意事项。

https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-configure-an-app-to-support-net-framework-4-or-4-5


All apps that host the common language runtime (CLR) need to start, or activate, the CLR in order to run managed code. Typically, a .NET Framework app runs on the version of the CLR that it was built on, but you can change this behavior for desktop apps by using an application configuration file (sometimes referred to as an app.config file). However, you cannot change the default activation behavior for Windows Store apps or Windows Phone apps by using an application configuration file. This article explains how to enable your desktop app to run on another version of the .NET Framework and provides an example of how to target version 4 or 4.5.

The version of the .NET Framework that an app runs on is determined in the following order:

  • Configuration file.

    If the application configuration file includes <supportedRuntime> entries that specify one or more .NET Framework versions, and one of those versions is present on the user's computer, the app runs on that version. The configuration file reads <supportedRuntime> entries in the order they are listed, and uses the first .NET Framework version listed that is present on the user's computer. (Use the <requiredRuntime> element for version 1.0.)

  • Compiled version.

    If there is no configuration file, but the version of the .NET Framework that the app was built on is present on the user's computer, the app runs on that version.

  • Latest version installed.

    If the version of the .NET Framework that the app was built on is not present and a configuration file does not specify a version in a <supportedRuntime> element, the app tries to run on the latest version of the .NET Framework that is present on the user's computer.

    However, .NET Framework 1.0, 1.1, 2.0, 3.0, and 3.5 apps do not automatically run on the .NET Framework 4 or later, and in some cases, the user may receive an error and may be prompted to install the .NET Framework 3.5. The activation behavior may also depend on the user’s operating system, because different versions of Windows system include different versions of the .NET Framework. If your app supports both the .NET Framework 3.5 and 4 or later, we recommend that you indicate this with multiple entries in the configuration file to avoid .NET Framework initialization errors. For more information, see Versions and Dependencies.

You might also want to configure your .NET Framework 3.5 apps to run on the .NET Framework 4 or 4.5, even on computers that have the .NET Framework 3.5 installed, to take advantage of the performance improvements in versions 4 and 4.5.

Important

We recommend that you always test your app on every .NET Framework version that you support. See Version Compatibility for information about upgrading your application to support later .NET Framework versions.

For information about modifying your .NET Framework 1.0 and 1.1 apps to support Windows 7 and Windows 8, see Migrating from the .NET Framework 1.1.

To configure your app to run on the .NET Framework 4 or 4.5

  1. Add or locate the configuration file for the .NET Framework project. The configuration file for an app is in the same directory and has the same name as the app, but has a .config extension. For example, for an app named MyExecutable.exe, the application configuration file is named MyExecutable.exe.config.

    To add a configuration file, on the Visual Studio menu bar, choose Project, Add New Item. Choose General from the left pane, and then choose Configuration File. Name the configuration file appName.exe.config. These menu choices are not available for Windows Store app or Windows phone app projects, because you cannot change the activation policy on those platforms.

  2. Add the <supportedRuntime> element as follows to the application configuration file:

    XML
  1. <configuration>  
      <startup>  
        <supportedRuntime version="<version>"/>  
      </startup>  
    </configuration>  
    

    where <version> specifies the CLR version that aligns with the .NET Framework version that your app supports. Use the following strings:

    • .NET Framework 1.0: "v1.0.3705"

    • .NET Framework 1.1: "v1.1.4322"

    • .NET Framework 2.0, 3.0, and 3.5: "v2.0.50727"

    • .NET Framework 4 and 4.5 (including point releases such as 4.5.1): "v4.0"

    You can add multiple <supportedRuntime> elements, listed in order of preference, to specify support for multiple versions of the .NET Framework.

The following table demonstrates how application configuration file settings and the .NET Framework versions installed on a computer determine the version that a .NET Framework 3.5 app runs on. The examples are specific to a .NET Framework 3.5 application, but you can use similar logic to target applications built with earlier .NET Framework versions. Note that the .NET Framework 2.0 version number (v2.0.50727) is used to specify the .NET Framework 3.5 in the application configuration file.

App.config file settingOn computer with version 3.5 installedOn computer with versions 3.5 and 4 or 4.5 installedOn computer with version 4 or 4.5 installed
NoneRuns on 3.5Runs on 3.5Displays error message that prompts user to install the correct version*
<supportedRuntime version="v2.0.50727"/>Runs on 3.5Runs on 3.5Displays error message that prompts user to install the correct version*
<supportedRuntime version="v2.0.50727"/>
<supportedRuntime version="v4.0"/>
Runs on 3.5Runs on 3.5Runs on 4 or 4.5
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727"/>
Runs on 3.5Runs on 4 or 4.5Runs on 4 or 4.5
<supportedRuntime version="v4.0"/>Displays error message that prompts user to install the correct version*Runs on 4 or 4.5Runs on 4 or 4.5

* For more information about this error message and ways to avoid it, see .NET Framework Initialization Errors: Managing the User Experience.

See Also

Migrating from the .NET Framework 1.1
Migration Guide


多源动态最优潮流的分布鲁棒优化方法(IEEE118节点)(Matlab代码实现)内容概要:本文介绍了基于Matlab代码实现的多源动态最优潮流的分布鲁棒优化方法,适用于IEEE118节点电力系统。该方法结合两阶段鲁棒模型与确定性模型,旨在应对电力系统中多源输入(如可再生能源)的不确定性,提升系统运行的安全性与经济性。文中详细阐述了分布鲁棒优化的建模思路,包括不确定性集合的构建、目标函数的设计以及约束条件的处理,并通过Matlab编程实现算法求解,提供了完整的仿真流程与结果分析。此外,文档还列举了大量相关电力系统优化研究案例,涵盖微电网调度、电动汽车集群并网、需求响应、储能配置等多个方向,展示了其在实际工程中的广泛应用价值。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事能源系统优化工作的工程师。; 使用场景及目标:①用于研究高比例可再生能源接入背景下电力系统的动态最优潮流问题;②支撑科研工作中对分布鲁棒优化模型的复现与改进;③为电力系统调度、规划及运行决策提供理论支持与仿真工具。; 阅读建议:建议读者结合提供的Matlab代码与IEEE118节点系统参数进行实操演练,深入理解分布鲁棒优化的建模逻辑与求解过程,同时可参考文中提及的其他优化案例拓展研究思路。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值