build: 版本升级到netcore3.0

This commit is contained in:
Argo Zhang 2019-09-18 13:53:19 +08:00
parent 74c5f7e2f5
commit 4986c14ded
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
12 changed files with 140 additions and 144 deletions

View File

@ -84,6 +84,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docker", "docker", "{85574E
src\admin\Bootstrap.Admin\Linux.Dockerfile = src\admin\Bootstrap.Admin\Linux.Dockerfile
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.Security.Mvc", "..\Utility\Bootstrap.Security.Mvc\src\Bootstrap.Security.Mvc\Bootstrap.Security.Mvc.csproj", "{A44BB5C0-BB27-482B-B1F1-DF79AC070C4E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -118,6 +120,10 @@ Global
{BC1C6D63-ADA9-4C3B-89F0-CEB191A86BF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC1C6D63-ADA9-4C3B-89F0-CEB191A86BF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC1C6D63-ADA9-4C3B-89F0-CEB191A86BF5}.Release|Any CPU.Build.0 = Release|Any CPU
{A44BB5C0-BB27-482B-B1F1-DF79AC070C4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A44BB5C0-BB27-482B-B1F1-DF79AC070C4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A44BB5C0-BB27-482B-B1F1-DF79AC070C4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A44BB5C0-BB27-482B-B1F1-DF79AC070C4E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -137,6 +143,7 @@ Global
{843811A2-FE49-410F-BF9F-9F1FB14A1DEE} = {C7F51A14-2D89-4D1F-AD78-C42B79AB0BF0}
{BC1C6D63-ADA9-4C3B-89F0-CEB191A86BF5} = {C7F51A14-2D89-4D1F-AD78-C42B79AB0BF0}
{E03B7391-B52F-4449-B400-5CD9DE01F085} = {41B6D37A-5E5E-42B3-85E4-D81A81E3D757}
{A44BB5C0-BB27-482B-B1F1-DF79AC070C4E} = {E03B7391-B52F-4449-B400-5CD9DE01F085}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {221EAE38-5F75-4391-9A48-E462A9F3B8FC}

View File

@ -12,7 +12,7 @@
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
</PropertyGroup>
<Target Condition=" '$(TargetFramework)' == 'netcoreapp2.2' " Name="PostBuild" AfterTargets="PostBuildEvent">
<Target Condition=" '$(TargetFramework)' == 'netcoreapp2.2' or '$(TargetFramework)' == 'netcoreapp3.0' " Name="PostBuild" AfterTargets="PostBuildEvent">
<Message Text="Copy file -> $(TargetDir)" Importance="high" />
<Copy Condition="'$(OS)' == 'Windows_NT'" DestinationFolder="$(TargetDir)" SourceFiles="$(MSBuildThisFileDirectory)src\admin\keys\Longbow.lic" SkipUnchangedFiles="true" />
<Copy Condition="'$(OS)' == 'UNIX'" DestinationFolder="$(TargetDir)" SourceFiles="$(MSBuildThisFileDirectory)src/admin/keys/Longbow.lic" SkipUnchangedFiles="true" />

View File

@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>
<PropertyGroup>
<DocumentationFile>$(MSBuildProjectName).xml</DocumentationFile>
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
@ -11,18 +12,14 @@
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.21" />
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.17" />
<PackageReference Include="Longbow.Configuration" Version="2.2.7" />
<PackageReference Include="Longbow.Tasks" Version="2.2.23" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.6" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Sentry.AspNetCore" Version="1.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Utility\Bootstrap.Security.Mvc\src\Bootstrap.Security.Mvc\Bootstrap.Security.Mvc.csproj" />
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj" />
</ItemGroup>

View File

@ -102,7 +102,7 @@ namespace Bootstrap.Admin.Controllers
/// </summary>
/// <param name="host"></param>
/// <returns></returns>
public ActionResult Profiles([FromServices]IHostingEnvironment host) => View(new ProfilesModel(this, host));
public ActionResult Profiles([FromServices]IWebHostEnvironment host) => View(new ProfilesModel(this, host));
/// <summary>
///

View File

@ -1,4 +1,4 @@
using Bootstrap.DataAccess;
using Bootstrap.DataAccess;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@ -24,7 +24,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// <returns></returns>
[HttpPost("{id}")]
[ButtonAuthorize(Url = "~/Admin/Profiles", Auth = "saveIcon")]
public JsonResult Post(string id, [FromServices]IHostingEnvironment env, [FromForm]DeleteFileCollection files)
public JsonResult Post(string id, [FromServices]IWebHostEnvironment env, [FromForm]DeleteFileCollection files)
{
if (!id.Equals("Delete", StringComparison.OrdinalIgnoreCase)) return new JsonResult(new object());
@ -72,7 +72,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// <returns></returns>
[HttpPost]
[ButtonAuthorize(Url = "~/Admin/Profiles", Auth = "saveIcon")]
public async Task<JsonResult> Post([FromServices]IHostingEnvironment env, IFormCollection files)
public async Task<JsonResult> Post([FromServices]IWebHostEnvironment env, IFormCollection files)
{
var previewUrl = string.Empty;
long fileSize = 0;
@ -128,4 +128,4 @@ namespace Bootstrap.Admin.Controllers.Api
return ret;
}
}
}
}

View File

@ -1,35 +1,33 @@
using Microsoft.AspNetCore.Authorization;
using Swashbuckle.AspNetCore.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen;
using System.Collections.Generic;
using Operation = Swashbuckle.AspNetCore.Swagger.Operation;
//using Microsoft.AspNetCore.Authorization;
//using Microsoft.OpenApi.Models;
//using Swashbuckle.AspNetCore.SwaggerGen;
//using System.Collections.Generic;
namespace Bootstrap.Admin
{
/// <summary>
///
/// </summary>
public class HttpHeaderOperation : IOperationFilter
{
/// <summary>
///
/// </summary>
/// <param name="operation"></param>
/// <param name="context"></param>
public void Apply(Operation operation, OperationFilterContext context)
{
if (operation.Parameters == null) operation.Parameters = new List<IParameter>();
//namespace Bootstrap.Admin
//{
// /// <summary>
// ///
// /// </summary>
// public class HttpHeaderOperation : IOperationFilter
// {
// /// <summary>
// ///
// /// </summary>
// /// <param name="operation"></param>
// /// <param name="context"></param>
// public void Apply(OpenApiOperation operation, OperationFilterContext context)
// {
// if (operation.Parameters == null) operation.Parameters = new List<OpenApiParameter>();
if (context.MethodInfo.GetCustomAttributes(typeof(AllowAnonymousAttribute), true).Length == 0)
{
operation.Parameters.Add(new NonBodyParameter()
{
Name = "Authorization", //添加Authorization头部参数
In = "header",
Type = "string",
Required = false
});
}
}
}
}
// if (context.MethodInfo.GetCustomAttributes(typeof(AllowAnonymousAttribute), true).Length == 0)
// {
// operation.Parameters.Add(new OpenApiParameter()
// {
// Name = "Authorization", //添加Authorization头部参数
// In = ParameterLocation.Header,
// Required = false
// });
// }
// }
// }
//}

View File

@ -30,7 +30,7 @@ namespace Bootstrap.Admin.Models
/// </summary>
/// <param name="host"></param>
/// <param name="controller"></param>
public ProfilesModel(ControllerBase controller, IHostingEnvironment host) : base(controller)
public ProfilesModel(ControllerBase controller, IWebHostEnvironment host) : base(controller)
{
if (host != null)
{

View File

@ -1,5 +1,5 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
namespace Bootstrap.Admin
{
@ -14,14 +14,14 @@ namespace Bootstrap.Admin
/// <param name="args"></param>
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
CreateHostBuilder(args).Build().Run();
}
/// <summary>
///
/// </summary>
/// <param name="args"></param>
/// <returns></returns>
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args).UseSentry().UseStartup<Startup>();
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(builder => builder.UseStartup<Startup>());
}
}

View File

@ -1,16 +1,15 @@
using Bootstrap.DataAccess;
using Longbow.Web;
using Longbow.Web.SignalR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Microsoft.Extensions.Hosting;
using System;
using System.Text.Encodings.Web;
using System.Text.Unicode;
@ -43,7 +42,7 @@ namespace Bootstrap.Admin
/// <param name="services"></param>
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All));
//services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All));
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
@ -51,39 +50,35 @@ namespace Bootstrap.Admin
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddCors();
services.AddLogging(builder => builder.AddFileLogger().AddDBLogger(ExceptionsHelper.Log));
//services.AddLogging(builder => builder.AddFileLogger().AddDBLogger(ExceptionsHelper.Log));
services.AddConfigurationManager();
services.AddCacheManager();
services.AddDbAdapter();
services.AddIPLocator(DictHelper.ConfigIPLocator);
services.AddOnlineUsers();
services.AddSignalR().AddJsonProtocalDefault();
services.AddSignalRExceptionFilterHandler<SignalRHub>((client, ex) => client.SendMessageBody(ex).ConfigureAwait(false));
//services.AddSignalR().AddJsonProtocalDefault();
//services.AddSignalRExceptionFilterHandler<SignalRHub>((client, ex) => client.SendMessageBody(ex).ConfigureAwait(false));
services.AddResponseCompression();
services.AddBootstrapAdminAuthentication().AddGitee(OAuthHelper.Configure).AddGitHub(OAuthHelper.Configure);
services.AddSwagger();
services.AddAuthorization(options => options.DefaultPolicy = new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build());
//services.AddSwagger();
services.AddButtonAuthorization(MenuHelper.AuthorizateButtons);
services.AddBootstrapAdminBackgroundTask();
services.AddHttpClient<GiteeHttpClient>();
services.AddAdminHealthChecks();
services.AddMvc(options =>
services.AddControllersWithViews(options =>
{
options.Filters.Add<BootstrapAdminAuthorizeFilter>();
options.Filters.Add<ExceptionFilter>();
options.Filters.Add<SignalRExceptionFilter<SignalRHub>>();
}).AddJsonOptions(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
JsonConvert.DefaultSettings = () => options.SerializerSettings;
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddApiVersioning(option =>
{
option.DefaultApiVersion = new ApiVersion(1, 0);
option.ReportApiVersions = true;
option.AssumeDefaultVersionWhenUnspecified = true;
option.ApiVersionReader = ApiVersionReader.Combine(new HeaderApiVersionReader("api-version"), new QueryStringApiVersionReader("api-version"));
});
//services.AddApiVersioning(option =>
//{
// option.DefaultApiVersion = new ApiVersion(1, 0);
// option.ReportApiVersions = true;
// option.AssumeDefaultVersionWhenUnspecified = true;
// option.ApiVersionReader = ApiVersionReader.Combine(new HeaderApiVersionReader("api-version"), new QueryStringApiVersionReader("api-version"));
//});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -92,7 +87,7 @@ namespace Bootstrap.Admin
/// </summary>
/// <param name="app"></param>
/// <param name="env"></param>
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseForwardedHeaders(new ForwardedHeadersOptions() { ForwardedHeaders = ForwardedHeaders.All });
if (env.IsDevelopment())
@ -109,21 +104,20 @@ namespace Bootstrap.Admin
app.UseHttpsRedirection();
app.UseResponseCompression();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseBootstrapAdminAuthentication(RoleHelper.RetrievesByUserName, RoleHelper.RetrievesByUrl, AppHelper.RetrievesByUserName);
app.UseBootstrapHealthChecks();
app.UseOnlineUsers(TraceHelper.Filter, TraceHelper.Save);
app.UseCacheManager();
app.UseSignalR(routes =>
//app.UseSwagger(Configuration["SwaggerPathBase"].TrimEnd('/'));
app.UseEndpoints(endpoints =>
{
routes.MapHub<SignalRHub>("/NotiHub");
routes.MapHub<TaskLogHub>("/TaskLogHub");
});
app.UseSwagger(Configuration["SwaggerPathBase"].TrimEnd('/'));
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
//endpoints.MapHub<SignalRHub>("/NotiHub");
//endpoints.MapHub<TaskLogHub>("/TaskLogHub");
//endpoints.MapHealthChecks("/healths");
endpoints.MapDefaultControllerRoute().RequireAuthorization();
});
}
}

View File

@ -1,58 +1,59 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.Swagger;
using System;
using System.IO;
//using Microsoft.AspNetCore.Authentication;
//using Microsoft.AspNetCore.Builder;
//using Microsoft.Extensions.DependencyInjection;
//using Microsoft.OpenApi.Models;
//using Swashbuckle.AspNetCore.Swagger;
//using System;
//using System.IO;
namespace Bootstrap.Admin
{
/// <summary>
///
/// </summary>
internal static class SwaggerExtensions
{
/// <summary>
///
/// </summary>
/// <param name="app"></param>
/// <param name="pathBase"></param>
public static void UseSwagger(this IApplicationBuilder app, string pathBase)
{
app.UseWhen(context => context.Request.Path.StartsWithSegments("/swagger"), builder =>
{
builder.Use(async (context, next) =>
{
if (!context.User.Identity.IsAuthenticated) await context.ChallengeAsync();
else await next();
});
});
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint($"{pathBase}/swagger/v1/swagger.json", "BootstrapAdmin API V1");
});
}
//namespace Bootstrap.Admin
//{
// /// <summary>
// ///
// /// </summary>
// internal static class SwaggerExtensions
// {
// /// <summary>
// ///
// /// </summary>
// /// <param name="app"></param>
// /// <param name="pathBase"></param>
// public static void UseSwagger(this IApplicationBuilder app, string pathBase)
// {
// app.UseWhen(context => context.Request.Path.StartsWithSegments("/swagger"), builder =>
// {
// builder.Use(async (context, next) =>
// {
// if (!context.User.Identity.IsAuthenticated) await context.ChallengeAsync();
// else await next();
// });
// });
// app.UseSwagger();
// app.UseSwaggerUI(c =>
// {
// c.SwaggerEndpoint($"{pathBase}/swagger/v1/swagger.json", "BootstrapAdmin API V1");
// });
// }
/// <summary>
///
/// </summary>
/// <param name="services"></param>
public static void AddSwagger(this IServiceCollection services)
{
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new Info
{
Version = "v1",
Title = "BootstrapAdmin API"
});
// /// <summary>
// ///
// /// </summary>
// /// <param name="services"></param>
// public static void AddSwagger(this IServiceCollection services)
// {
// services.AddSwaggerGen(options =>
// {
// options.SwaggerDoc("v1", new OpenApiInfo
// {
// Version = "v1",
// Title = "BootstrapAdmin API"
// });
//Set the comments path for the swagger json and ui.
var xmlPath = Path.Combine(AppContext.BaseDirectory, "Bootstrap.Admin.xml");
options.IncludeXmlComments(xmlPath);
options.OperationFilter<HttpHeaderOperation>(); // 添加httpHeader参数
});
}
}
}
// //Set the comments path for the swagger json and ui.
// var xmlPath = Path.Combine(AppContext.BaseDirectory, "Bootstrap.Admin.xml");
// options.IncludeXmlComments(xmlPath);
// options.OperationFilter<HttpHeaderOperation>(); // 添加httpHeader参数
// });
// }
// }
//}

View File

@ -18,7 +18,7 @@ namespace Bootstrap.DataAccess.SqlServer
[Fact]
public void Authenticate_Ok()
{
Assert.True(UserHelper.Authenticate("Admin", "123789", u => u.Ip = "::1"));
Assert.True(UserHelper.Authenticate("Admin", "123789"));
}
/// <summary>
@ -27,7 +27,7 @@ namespace Bootstrap.DataAccess.SqlServer
[Fact]
public void Authenticate_Fail()
{
Assert.False(UserHelper.Authenticate("Admin-NotExists", "123789", u => u.Ip = "::1"));
Assert.False(UserHelper.Authenticate("Admin-NotExists", "123789"));
}
[Fact]

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<IsPackable>false</IsPackable>
<DebugType>full</DebugType>
</PropertyGroup>
@ -11,7 +11,6 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="2.2.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />