利用vs2022 创建一个空的Core项目
下一步,添加工程名称和选择路径。即可
Startup.cs的解释
public class Startup
{
//配置容器服务
public void ConfigureServices(IServiceCollection services)
{
}
// 配置HTTP请求处理管道当中一些配置
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async cOntext=>
{
await context.Response.WriteAsync("Hello World!");
});
});
}
}
Program.cs的解释
public class Program
{
//主启动
public static void Main(string[] args)
{
//对CreateHostBuilder(args).Build().Run();的分布解释
//内部,会配置kestrel服务器,IIS相关,其他配置。
IHostBuilder builder = Host.CreateDefaultBuilder(args);
builder.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup
});
IHost webHost = builder.Build();
webHost.Run();
//CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup
});
}2.启动