將 ASP.NET Core 2.2 遷移至 ASP.NET Core 3.0 需要注意的地方記錄在這篇隨筆中。
TargetFramework 改為 netcoreapp3.0
<TargetFramework>netcoreapp3.0</TargetFramework>
從 PackageReference 中移除 Microsoft.AspNetCore.App
<PackageReference Include="Microsoft.AspNetCore.App" />
Program 中 WebHost 改為 Host
public class Program { public static void Main(string[] args) { CreateHostBuilder(args).Build().Run(); } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); }); }
Startup 中 app.UseMvc() 改為 app.UseRouting() 與 app.UseEndpoints()
app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); });
.NET Core 3.0 SDK 的 docker 映象
mcr.microsoft.com/dotnet/core/sdk:3.0
ASP.NET Core 3.0 runtime 的 docker 映象
mcr.microsoft.com/dotnet/core/aspnet:3.0
Web API 響應的 json 資料中文被編碼的問題(詳見博問)
services.AddMvc().AddNewtonsoftJson();
EF Core 3.0 配置一對一關係(生成 INNER JOIN SQL 語句)
builder.HasOne(p => p.ViewCount)
.WithOne()
.IsRequired()
.HasPrincipalKey<ViewCount>(vc => vc.PostId);