[Backend] Core framework version and release time and the structure of the .net 6.0 startup file

2023, Week 35, Article 1. Give yourself a goal, and then insist that there will always be a receipt, if you don’t believe me, try it!
.NET Core is a cross-platform open source framework for building modern applications. It has some important differences and release times in different versions

insert image description here

1. Core version and release time

Here is a brief overview of the major releases:

1.1, NET Core 1.x series

Released in 2016.
It is the initial version of .NET Core, providing a cross-platform, high-performance and lightweight development experience.
However, due to limitations and limitations of the initial release, this series is no longer maintained and supported.

1.2, .NET Core 2.x series

Released in 2017.
This series brings many important improvements and features, such as better performance, more powerful development tools and wider platform support.
It also enhances compatibility with .NET Framework and introduces ASP.NET Core 2.x for building web applications.

1.3, .NET Core 3.x series

Released in 2019.
This series introduces many exciting features, including support for Windows desktop application development, modernization and improvement of WPF and Windows Forms, language features of C# 8.0, and more.
Additionally, the new .NET Core 3.1 release was introduced as a Long Term Support (LTS) release.

1.4, .NET 5 (Milestone)

Released in 2020.
This is a major release that brings together the capabilities of .NET Framework and .NET Core into a single unified platform.
It is designed to provide higher performance, more optional components, and broader support.

1.5、.NET 6

Released November 2021.
This will be a major release that will bring more improvements, new features and improved performance.
.NET 6 supports multiple operating systems and platforms, including Windows, macOS, and Linux, while also providing support for web, mobile, and cloud application types.

In .NET 6, developers can use new language features, enhanced tools and framework components to build high-performance and modern applications.
In addition, .NET 6 also introduces a new MAUI (Multi-platform App UI) framework for building cross-platform native applications, including support for mobile and desktop platforms.

It should be noted that starting from .NET 5, Microsoft decided to abandon the "Core" naming and use the year as the version number instead. This is to better reflect the continuity and consistency of the .NET platform.

2. Core and C# versions

In .NET Core, each version is paired with a corresponding version of the C# language.
The following are the correspondence between some common .NET Core versions and the corresponding C# language versions:

1) .NET Core 1.x: Corresponding to C# 6.0
2) .NET Core 2.x: Corresponding to C# 7.0 and C# 7.1
3) .NET Core 3.x: Corresponding to C# 8.0
4) .NET 5: Corresponding to C# 9.0
5) .NET 6: corresponding to C# 10.0

It should be noted that the C# language version is not fully bound to the .NET Core version, which means that you can use the lower version of the C# language features to develop in a higher version of .NET Core.
However, if you want to use the latest features and improvements of a particular version of the C# language, you may need to use the corresponding .NET Core version.

Also, note that the official support of the C# language version depends on the version of the development tool (such as Visual Studio) you are using.
Make sure that the development tool used supports the required C# language version, and write code according to the corresponding syntax and rules.

It should be pointed out that the above are common correspondences, and the specific version correspondences may vary according to the actual situation.
Therefore, it is recommended to consult the corresponding documentation or official release information when using a specific .NET Core version to determine the C# language version corresponding to the version.

3. The .net core 6.0 startup file
In .NET 6.0, there are some changes in how the Startup file is created compared to previous versions.
Here are the steps to create a Startup file in .NET 6.0:

3.1. Open the program file

First, in your project (such as an ASP.NET Core web application), open Program.csthe file.

In CreateHostBuilderthe method, register and configure the application's services and settings.
Here you can use .ConfigureServicesthe and .Configuremethods to add services and configure the application.

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);

// 配置服务
builder.Services.AddControllersWithViews();
// ...

// 配置应用程序
var app = builder.Build();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
    
    
    endpoints.MapControllers();
    // ...
});

app.Run();

3.2. Open the startup file

Make sure there is a file called in your project Startup.cs. If the file does not exist, it can be created manually.
Open Startup.csthe file and make sure it contains namespace references and class definitions.

using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace YourNamespace
{
    
    
    public class Startup
    {
    
    
        public IConfiguration Configuration {
    
     get; }

        public Startup(IConfiguration configuration)
        {
    
    
            Configuration = configuration;
        }

        // ConfigureServices 方法用于配置应用程序的服务
        public void ConfigureServices(IServiceCollection services)
        {
    
    
            services.AddControllersWithViews();
            // ... 添加其他服务配置
        }

        // Configure 方法用于配置应用程序的请求处理管道
        public void Configure(IApplicationBuilder app)
        {
    
    
            if (env.IsDevelopment())
            {
    
    
                app.UseDeveloperExceptionPage();
            }
            else
            {
    
    
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            // 配置端点路由
            app.UseEndpoints(endpoints =>
            {
    
    
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}"
                );
            });
        }
    }
}

Make sure to set the startup class to the class in the method Program.csof the .CreateHostBuilderStartup

builder.ConfigureServices((hostContext, services) =>
{
    
    
    // ...
}).ConfigureWebHostDefaults(webBuilder =>
{
    
    
    webBuilder.UseStartup<YourNamespace.Startup>();
});

You have now successfully created the Startup file and defined the application's service and request processing pipeline configuration.
You can add more middleware, configuration options and services in the Startup class to suit your application needs.

Guess you like

Origin blog.csdn.net/lmy_520/article/details/132402417