You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

迁移至.NET Core时,app.config中<supportedRuntime>节点的处理方式咨询

Migrating the <startup> Section from .NET Framework's app.config to .NET Core

Great question! When moving from .NET Framework to .NET Core (including .NET 5+), that <startup> block from your app.config is no longer relevant—you can safely delete it entirely. Here's why and what to do instead:

  • Delete the <startup> code completely
    The <supportedRuntime> element was specific to .NET Framework's CLR bootstrapping process, which tells the system which version of the .NET Framework runtime to use. .NET Core uses a different approach to manage runtime versions, so this section serves no purpose here and can be removed without any side effects.

  • Define your target framework in the .csproj file
    Instead of configuring the runtime in app.config, .NET Core uses the project file (.csproj) to specify the target framework. You'll find a <TargetFramework> element (or <TargetFrameworks> for multi-targeting projects) that handles this. For example:

    <!-- Target a single .NET Core version -->
    <TargetFramework>net8.0</TargetFramework>
    

    If you need to maintain compatibility with your original .NET Framework 4.7.1 while migrating, you can multi-target both frameworks:

    <TargetFrameworks>net471;net8.0</TargetFrameworks>
    

    This lets your project build for both .NET Framework 4.7.1 and the .NET Core version of your choice.

  • For other app.config settings
    If your app.config has other sections like <appSettings> or <connectionStrings>, those can be migrated to appsettings.json (the recommended configuration approach for .NET Core) or you can keep using app.config by adding the System.Configuration.ConfigurationManager NuGet package to maintain backward compatibility. But again, the <startup> section is obsolete in .NET Core and should be deleted.

内容的提问来源于stack exchange,提问作者Bizhan

火山引擎 最新活动