迁移至.NET Core时,app.config中<supportedRuntime>节点的处理方式咨询
<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 inapp.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 yourapp.confighas other sections like<appSettings>or<connectionStrings>, those can be migrated toappsettings.json(the recommended configuration approach for .NET Core) or you can keep usingapp.configby adding theSystem.Configuration.ConfigurationManagerNuGet package to maintain backward compatibility. But again, the<startup>section is obsolete in .NET Core and should be deleted.
内容的提问来源于stack exchange,提问作者Bizhan




