Skip to content

Commit 028e830

Browse files
committed
Migrated to .NET 6. Considered .NET Core 3.1. but it goes End of Support in December).
1 parent 27d8fab commit 028e830

File tree

3 files changed

+30
-35
lines changed

3 files changed

+30
-35
lines changed

Program.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.AspNetCore;
77
using Microsoft.AspNetCore.Hosting;
88
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Hosting;
910
using Microsoft.Extensions.Logging;
1011

1112
namespace pipelines_dotnet_core
@@ -14,11 +15,15 @@ public class Program
1415
{
1516
public static void Main(string[] args)
1617
{
17-
CreateWebHostBuilder(args).Build().Run();
18+
CreateHostBuilder(args).Build().Run();
1819
}
1920

20-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
21-
WebHost.CreateDefaultBuilder(args)
22-
.UseStartup<Startup>();
21+
public static IHostBuilder CreateHostBuilder(string[] args) =>
22+
Host.CreateDefaultBuilder(args)
23+
.ConfigureWebHostDefaults(builder =>
24+
{
25+
builder.UseStartup<Startup>();
26+
});
27+
2328
}
2429
}

Startup.cs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
5-
using Microsoft.AspNetCore.Builder;
1+
using Microsoft.AspNetCore.Builder;
62
using Microsoft.AspNetCore.Hosting;
73
using Microsoft.AspNetCore.Http;
8-
using Microsoft.AspNetCore.HttpsPolicy;
9-
using Microsoft.AspNetCore.Mvc;
104
using Microsoft.Extensions.Configuration;
115
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.Extensions.Hosting;
127

138
namespace pipelines_dotnet_core
149
{
@@ -24,41 +19,43 @@ public Startup(IConfiguration configuration)
2419
// This method gets called by the runtime. Use this method to add services to the container.
2520
public void ConfigureServices(IServiceCollection services)
2621
{
27-
services.Configure<CookiePolicyOptions>(options =>
28-
{
22+
_ = services.Configure<CookiePolicyOptions>(options =>
23+
{
2924
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
3025
options.CheckConsentNeeded = context => true;
31-
options.MinimumSameSitePolicy = SameSiteMode.None;
32-
});
26+
options.MinimumSameSitePolicy = SameSiteMode.None;
27+
});
3328

3429

35-
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
30+
services.AddRazorPages();
3631
}
3732

3833
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
39-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
34+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
4035
{
41-
if (env.IsDevelopment())
42-
{
43-
app.UseDeveloperExceptionPage();
44-
}
45-
else
36+
if (!env.IsDevelopment())
4637
{
4738
app.UseExceptionHandler("/Home/Error");
4839
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
4940
app.UseHsts();
5041
}
42+
else
43+
{
44+
app.UseDeveloperExceptionPage();
45+
}
5146

5247
app.UseHttpsRedirection();
5348
app.UseStaticFiles();
5449
app.UseCookiePolicy();
5550

56-
app.UseMvc(routes =>
51+
app.UseRouting();
52+
53+
app.UseEndpoints(endpoints =>
5754
{
58-
routes.MapRoute(
55+
endpoints.MapControllerRoute(
5956
name: "default",
60-
template: "{controller=Home}/{action=Index}/{id?}");
57+
pattern: "{controller=Home}/{action=Index}/{id?}");
6158
});
6259
}
6360
}
64-
}
61+
}

pipelines-dotnet-core.csproj

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
66
<RootNamespace>pipelines_dotnet_core</RootNamespace>
77
</PropertyGroup>
8-
9-
10-
<ItemGroup>
11-
<PackageReference Include="Microsoft.AspNetCore.App" />
12-
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
13-
</ItemGroup>
14-
15-
</Project>
8+
</Project>

0 commit comments

Comments
 (0)