.net core2.2升级.net core3.1/.net5
2020-12-22 06:31
标签:stat ash run 新版本 sem tst ddc host mapr 1.目标框架设置为.net core3.1/.net5 2.将所有的nuget包升级为最新版本 3.需要改动的一些地方 Program.cs 更改为: 4.Startup.cs ConfigureServices方法 (1)设置api json返回格式 (2)路由变化 Configure方法 (3)一些问题 安装包:Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation ConfigureServices方法 (4)检测到包降级: System.Runtime.Handles 从 4.3.0 降级到 4.0.1。直接从项目引用包以选择不同版本。 MyBlog.Swagger -> Swashbuckle.AspNetCore.Filters 6.0.1 -> Scrutor 3.0.1 -> Microsoft.Extensions.DependencyModel 2.1.0 -> Microsoft.DotNet.PlatformAbstractions 2.1.0 -> System.IO.FileSystem 4.0.1 -> runtime.unix.System.IO.FileSystem 4.3.0 -> System.Runtime.Handles (>= 4.3.0) MyBlog.Swagger -> Swashbuckle.AspNetCore.Filters 6.0.1 -> Scrutor 3.0.1 -> Microsoft.Extensions.DependencyModel 2.1.0 -> Microsoft.DotNet.PlatformAbstractions 2.1.0 -> System.IO.FileSystem 4.0.1 -> System.Runtime.Handles (>= 4.0.1) 在对应项目下安装System.Runtime.Handles 4.3.0版本的包就好了 .net core2.2升级.net core3.1/.net5 标签:stat ash run 新版本 sem tst ddc host mapr 原文地址:https://www.cnblogs.com/LiChen19951127/p/13986456.html public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup
using Microsoft.Extensions.Hosting;
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
//.netCore2.2
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2).AddJsonOptions(
opt => {
opt.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm";
});
//.net Core3.1
services.AddControllersWithViews(option =>
{
option.EnableEndpointRouting = false;
}).SetCompatibilityVersion(CompatibilityVersion.Latest).AddControllersAsServices().AddNewtonsoftJson
(
json =>
{
//统一设置JsonResult
json.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
}
);
//.net core2.2
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default_area",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areas",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
});
//.net 5
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default_area",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
});
services.AddControllersWithViews().AddRazorRuntimeCompilation();
文章标题:.net core2.2升级.net core3.1/.net5
文章链接:http://soscw.com/index.php/essay/37514.html