Update AspNetCore-React-WebApp from ASP. NET Core 2.2 to 3.1 (#1)
* update to .Net 3.1 * Update README.md * clean up code * Update README.md * update NSwag to 13.5.0 * Update README.md * update backend dependencies to latestversions * clean up code * update README.md * update to use generic host * Update README * delete unnecessary comments * update dotnet-core.yml * update dotnet-core.yml * update dotnet-core.yml * working on fixing build issue * add solution file to yml * change configuration in nswag.json * Update README.md
This commit is contained in:
Родитель
31131da1c2
Коммит
fd4ecf285c
|
@ -22,7 +22,7 @@ jobs:
|
|||
run: dotnet restore
|
||||
- name: Build
|
||||
working-directory: service
|
||||
run: dotnet build --configuration Release --no-restore
|
||||
run: dotnet build Microsoft.DSX.ProjectTemplate.sln --configuration Release --no-restore
|
||||
- name: Test
|
||||
working-directory: service
|
||||
run: dotnet test --no-restore --verbosity normal
|
||||
|
|
18
README.md
18
README.md
|
@ -1,5 +1,21 @@
|
|||
# Overview
|
||||
Web app template by [DSX](https://deviceswiki.com/wiki/DSX)
|
||||
Web app template by the Microsoft Devices Software Experiences team.
|
||||
|
||||
# Updates
|
||||
## Backend Architecture
|
||||
- Solution has been updated to use and support ASP.NET Core 3.1
|
||||
- Target frameworks in csproj files have been changed from 2.2 to 3.1.
|
||||
- All unnecessary packages have been removed
|
||||
- Relevant packages have been updated to their latest versions
|
||||
- Entity Framework Packages have been changed to 3.1.4
|
||||
- NSwag has been updated to 13.5.0
|
||||
- NSwag.MSBuild has been updated 13.5.0
|
||||
- Target frameworks and runtimes have been changed in nswag.json to support ASP .NET Core 3.1
|
||||
- Code has been changed to follow guidelines for ASP .NET Core 3.1 found in the [documentation.](https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio)
|
||||
- Changes to Startup
|
||||
- ``` .AddMvc() ``` has been deprecated in ASP .NET Core 3.1 and replaced with ``` .AddControllers() ```
|
||||
- ``` .UseMvc() ``` has been deprecated and replaced with ``` .UseRouting() ``` and ``` .UseEndpoints() ```
|
||||
- ``` IHostingEnvironment ``` is obsolete and replaced with ``` IHostEnvironment ```
|
||||
|
||||
# Frontend Architecture
|
||||
- React with TypeScript
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc.Filters;
|
|||
using Microsoft.DSX.ProjectTemplate.Data.DTOs;
|
||||
using Microsoft.DSX.ProjectTemplate.Data.Exceptions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.DSX.ProjectTemplate.API
|
||||
|
@ -15,13 +16,13 @@ namespace Microsoft.DSX.ProjectTemplate.API
|
|||
/// <remarks>https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters#exception-filters</remarks>
|
||||
public class GlobalExceptionFilter : IExceptionFilter
|
||||
{
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly IHostEnvironment _hostingEnvironment;
|
||||
private readonly ILogger<GlobalExceptionFilter> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GlobalExceptionFilter"/> class.
|
||||
/// </summary>
|
||||
public GlobalExceptionFilter(IHostingEnvironment hostingEnvironment, ILogger<GlobalExceptionFilter> logger)
|
||||
public GlobalExceptionFilter(IHostEnvironment hostingEnvironment, ILogger<GlobalExceptionFilter> logger)
|
||||
{
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
|
|
|
@ -1,20 +1,23 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<UserSecretsId>95966057-82fe-4a76-8bc9-c168781ea2f9</UserSecretsId>
|
||||
<LangVersion>7.1</LangVersion>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MediatR" Version="7.0.0" />
|
||||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
||||
<PackageReference Include="NSwag.AspNetCore" Version="13.0.4" />
|
||||
<PackageReference Include="NSwag.MSBuild" Version="13.0.4" />
|
||||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4" />
|
||||
<PackageReference Include="NSwag.AspNetCore" Version="13.5.0" />
|
||||
<PackageReference Include="NSwag.MSBuild" Version="13.5.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -24,10 +27,8 @@
|
|||
|
||||
<!-- https://github.com/RicoSuter/NSwag/wiki/Assembly-loading#net-core -->
|
||||
<!-- build TypeScript client and DTOs for this backend -->
|
||||
<Target Name="NSwag" AfterTargets="Build">
|
||||
<Copy SourceFiles="@(Reference)" DestinationFolder="$(OutDir)References" />
|
||||
<Exec Command="$(NSwagExe_Core22) run nswag.json /variables:OutDir=$(OutDir)" />
|
||||
<RemoveDir Directories="$(OutDir)References" />
|
||||
</Target>
|
||||
<Target Name="NSwag" AfterTargets="Build">
|
||||
<Exec Command="$(NSwagExe_Core31) run nswag.json /variables:Configuration=$(Configuration)" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -4,34 +4,44 @@ using Microsoft.AspNetCore.Hosting;
|
|||
using Microsoft.DSX.ProjectTemplate.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.DSX.ProjectTemplate.API
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var webHost = CreateWebHostBuilder(args).Build();
|
||||
var logger = webHost.Services.GetRequiredService<ILogger<Program>>();
|
||||
|
||||
//var webHost = CreateWebHostBuilder(args).Build();
|
||||
|
||||
IHost host = CreateHostBuilder(args).Build();
|
||||
var logger = host.Services.GetRequiredService<ILogger<Program>>();
|
||||
|
||||
try
|
||||
{
|
||||
RunDatabaseMigrations(webHost, logger);
|
||||
webHost.Run();
|
||||
RunDatabaseMigrations(host, logger);
|
||||
host.Run();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogCritical(ex, ex.Message);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>();
|
||||
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
});
|
||||
|
||||
private static void RunDatabaseMigrations(IWebHost host, ILogger logger)
|
||||
|
||||
private static void RunDatabaseMigrations(IHost host, ILogger logger)
|
||||
{
|
||||
logger.LogInformation($"Running database migrations");
|
||||
using (var serviceScope = host.Services.CreateScope())
|
||||
|
|
|
@ -10,14 +10,14 @@ using Microsoft.DSX.ProjectTemplate.Data.Services;
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NSwag.AspNetCore;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
[assembly: ApiConventionType(typeof(DefaultApiConventions))]
|
||||
namespace Microsoft.DSX.ProjectTemplate.API
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration, IHostingEnvironment hostingEnvironment)
|
||||
public Startup(IConfiguration configuration, IHostEnvironment hostingEnvironment)
|
||||
{
|
||||
Configuration = configuration;
|
||||
HostingEnvironment = hostingEnvironment;
|
||||
|
@ -26,7 +26,7 @@ namespace Microsoft.DSX.ProjectTemplate.API
|
|||
readonly string CorsPolicy = "CorsPolicy";
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
public IHostingEnvironment HostingEnvironment { get; }
|
||||
public IHostEnvironment HostingEnvironment { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
|
@ -39,14 +39,9 @@ namespace Microsoft.DSX.ProjectTemplate.API
|
|||
options.AddPolicy(CorsPolicy,
|
||||
builder => builder.AllowAnyOrigin()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
.AllowCredentials());
|
||||
.AllowAnyHeader());
|
||||
})
|
||||
.AddMvc(options =>
|
||||
{
|
||||
options.Filters.Add(typeof(GlobalExceptionFilter));
|
||||
})
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||
.AddControllers();
|
||||
|
||||
// Register Entity Framework Core
|
||||
ConfigureDatabase(services);
|
||||
|
@ -87,7 +82,7 @@ namespace Microsoft.DSX.ProjectTemplate.API
|
|||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public virtual void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
|
@ -100,7 +95,7 @@ namespace Microsoft.DSX.ProjectTemplate.API
|
|||
}
|
||||
|
||||
// Register the Swagger generator and the Swagger UI middlewares
|
||||
app.UseSwagger();
|
||||
app.UseOpenApi();
|
||||
app.UseSwaggerUi3();
|
||||
|
||||
if (!env.IsEnvironment("Test"))
|
||||
|
@ -108,9 +103,16 @@ namespace Microsoft.DSX.ProjectTemplate.API
|
|||
app.UseHttpsRedirection();
|
||||
}
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseCors(CorsPolicy);
|
||||
|
||||
app.UseMvc();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,13 @@ using Microsoft.DSX.ProjectTemplate.Data.Utilities;
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Microsoft.DSX.ProjectTemplate.API
|
||||
{
|
||||
public class TestStartup : Startup
|
||||
{
|
||||
public TestStartup(IConfiguration configuration, IHostingEnvironment hostingEnvironment)
|
||||
public TestStartup(IConfiguration configuration, IHostEnvironment hostingEnvironment)
|
||||
: base(configuration, hostingEnvironment)
|
||||
{
|
||||
}
|
||||
|
@ -25,7 +26,7 @@ namespace Microsoft.DSX.ProjectTemplate.API
|
|||
.AddTransient<TestDataSeeder>();
|
||||
}
|
||||
|
||||
public override void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
// perform all configuration in the normal startup
|
||||
base.Configure(app, env);
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
{
|
||||
"runtime": "NetCore22",
|
||||
"runtime": "NetCore31",
|
||||
"defaultVariables": null,
|
||||
"documentGenerator": {
|
||||
"aspNetCoreToOpenApi": {
|
||||
"project": "Microsoft.DSX.ProjectTemplate.API.csproj",
|
||||
"msBuildProjectExtensionsPath": null,
|
||||
"configuration": "Debug",
|
||||
"configuration": "$(Configuration)",
|
||||
"runtime": null,
|
||||
"targetFramework": "netcoreapp2.2",
|
||||
"targetFramework": "netcoreapp3.1",
|
||||
"noBuild": true,
|
||||
"verbose": true,
|
||||
"workingDirectory": null,
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<LangVersion>7.1</LangVersion>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MediatR" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<LangVersion>7.1</LangVersion>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -12,10 +12,11 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="8.1.1" />
|
||||
<PackageReference Include="MediatR" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.4" />
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
using Microsoft.DSX.ProjectTemplate.Data.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
//using Microsoft.AspNetCore.Mvc.NewtonsoftJson;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Microsoft.DSX.ProjectTemplate.Data
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.DSX.ProjectTemplate.Test
|
||||
|
@ -14,9 +15,11 @@ namespace Microsoft.DSX.ProjectTemplate.Test
|
|||
/// </summary>
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
|
||||
builder
|
||||
.UseEnvironment("Test")
|
||||
.UseStartup<TStartup>();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,23 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
|
||||
<LangVersion>7.1</LangVersion>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="5.6.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.2.4" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.0" />
|
||||
<PackageReference Include="Moq" Version="4.11.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
Загрузка…
Ссылка в новой задаче