首先跟着官网 step by step
https://docs.microsoft.com/en-us/aspnet/core/migration/21-to-22?view=aspnetcore-2.2&tabs=visual-studio
Bug 1
发现一个 odata routing issue
https://github.com/Microsoft/aspnet-api-versioning/issues/361
因为 2.2 router 有升级, 貌似 odata 没有跟上.
https://blogs.msdn.microsoft.com/webdev/2018/08/27/asp-net-core-2-2-0-preview1-endpoint-routing/
目前只好先关上它
options.EnableEndpointRouting = false;
然后继续追踪
https://github.com/OData/WebApi/issues/1707
Bug 2
https://github.com/aspnet/AspNetCore/issues/6166
在做 webapi 又跨域的情况下, 游览器会发送 option request , 然而因为 2.2 有对 http2 之类的升级, 好像导致了 iis 的返回有点问题.
具体原因我就不管了. 反正就是用 work around 顶一顶先.
app.Use(async (ctx, next) => { await next(); if (ctx.Response.StatusCode == 204) { ctx.Response.ContentLength = 0; } });
持续追踪 https://github.com/aspnet/AspNetCore/issues/4398
Bug 3
serilog-extensions-logging-file 好像不能用了...虽然这东西本来就没有维护了.
那就找替代吧.
https://andrewlock.net/creating-a-rolling-file-logging-provider-for-asp-net-core-2-0/
https://nblumhardt.com/2017/08/use-serilog/
https://github.com/serilog/serilog-settings-configuration
https://stackoverflow.com/questions/40880261/configuring-serilog-rollingfile-with-appsettings-json
https://nblumhardt.com/2016/03/reading-logger-configuration-from-appsettings-json/
https://github.com/serilog/serilog-aspnetcore
https://github.com/serilog/serilog-sinks-file
appsetting.json
"Serilog": { "MinimumLevel": { "Default": "Information", "Override": { "Microsoft": "Information", "System": "Warning", "Hangfire": "Warning" } }, "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], "WriteTo": [ { "Name": "Console" }, { "Name": "File", "Args": { "path": "Log/log.txt", "rollingInterval": 3 } } ] },
main.cs
public static void Main(string[] args) { CurrentDirectoryHelpers.SetCurrentDirectory(); var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true) .AddEnvironmentVariables() .Build(); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(configuration) .CreateLogger(); WebHost.CreateDefaultBuilder(args) .UseUrls("http://192.168.1.152:61547") .ConfigureSecretFromCloud(skipInDevelopmentMode: true) .UseSerilog() .UseStartup<Startup>().Build().Run(); }
替代方案很简单. 但是 2.2 有 bug !
https://github.com/aspnet/AspNetCore/issues/4206
因为 serilog 是在 main.cs 去获取 appsetting.json 然后 setup config 的. 而 2.2 iis 情况下有一个叫 In-Progress 的鬼.
它会把 path 给弄不清楚. 幸好微软团队及时给了 work around 参考上面的 gitHub, 对话下方就有 word around 了.