Skip to content

Commit 1665ee7

Browse files
committed
chore: add tfm net10.0
1 parent 826393b commit 1665ee7

File tree

19 files changed

+138
-195
lines changed

19 files changed

+138
-195
lines changed

.github/workflows/PublishNugetPackage.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,34 @@ jobs:
1010

1111
runs-on: ubuntu-latest
1212

13+
permissions:
14+
id-token: write
15+
1316
steps:
1417
- uses: actions/checkout@v4
1518
- name: Setup .NET Core SDK
1619
uses: actions/setup-dotnet@v4
1720
with:
1821
dotnet-version: |
19-
8.0.x
22+
8.x
2023
9.x
24+
10.x
2125
- name: restore dependencies
2226
run: dotnet restore
2327
- name: build
24-
run: dotnet build --no-restore -c Release ./src/Cuture.AspNetCore.ResponseAutoWrapper/Cuture.AspNetCore.ResponseAutoWrapper.csproj
28+
run: dotnet build --no-restore -c Release
29+
- name: test
30+
run: dotnet test --no-restore -c Release
2531
- name: pack
2632
run: dotnet pack -c Release -o ./output --include-symbols
33+
34+
- name: NuGet login
35+
uses: NuGet/login@v1
36+
id: login
37+
with:
38+
user: ${{ secrets.NUGET_USER }}
39+
2740
- name: push package
2841
shell: pwsh
2942
working-directory: ./output
30-
run: Get-ChildItem -File -Filter '*.nupkg' | ForEach-Object { dotnet nuget push $_ -k ${{secrets.NUGET_KEY}} -s https://api.nuget.org/v3/index.json --no-service-endpoint --skip-duplicate; dotnet nuget push $_ -k ${{secrets.NUGET_GITHUB_KEY}} -s https://nuget.pkg.github.com/StratosBlue/index.json --no-service-endpoint --skip-duplicate; }
43+
run: Get-ChildItem -File -Filter '*.nupkg' | ForEach-Object { dotnet nuget push $_ -k ${{steps.login.outputs.NUGET_API_KEY}} -s https://api.nuget.org/v3/index.json --no-service-endpoint --skip-duplicate; dotnet nuget push $_ -k ${{secrets.NUGET_GITHUB_KEY}} -s https://nuget.pkg.github.com/StratosBlue/index.json --no-service-endpoint --skip-duplicate; }

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
3+
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
44

55
<Nullable>enable</Nullable>
66
<LangVersion>latest</LangVersion>

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
MIT License
1+
MIT License
22

3-
Copyright (c) 2021 Stratos
3+
Copyright (c) 2026 Stratos
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

global.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
{
1+
{
22
"msbuild-sdks": {
3-
"MSTest.Sdk": "3.8.3"
3+
"MSTest.Sdk": "4.0.2"
4+
},
5+
"test": {
6+
"runner": "Microsoft.Testing.Platform"
47
}
58
}

sample/CustomStructureWebApplication/CustomStructureWebApplication.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net8.0</TargetFrameworks>
4+
<TargetFrameworks>net10.0</TargetFrameworks>
55

66
<OpenApiGenerateDocuments>false</OpenApiGenerateDocuments>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.*" />
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0" />
11+
<PackageReference Include="SwaggerUI.AspNetCore" Version="5.30.2" />
1112
</ItemGroup>
1213

1314
<ItemGroup>
Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,46 @@
1-
using Microsoft.AspNetCore.Hosting;
1+
using System.Diagnostics;
2+
using CustomStructureWebApplication;
3+
using Microsoft.AspNetCore.Builder;
4+
using Microsoft.Extensions.DependencyInjection;
25
using Microsoft.Extensions.Hosting;
36

4-
namespace CustomStructureWebApplication;
7+
var builder = WebApplication.CreateBuilder(args);
58

6-
public class Program
7-
{
8-
#region Public 方法
9+
builder.Services.AddControllers();
10+
builder.Services.AddOpenApi();
11+
12+
builder.Services.AddResponseAutoWrapper<CommonResponse<object>, string, RichMessage>()
13+
.ConfigureWrappers(options => options.AddWrappers<CustomWrapper>());
914

10-
public static IHostBuilder CreateHostBuilder(string[] args) =>
11-
Host.CreateDefaultBuilder(args)
12-
.ConfigureWebHostDefaults(webBuilder =>
13-
{
14-
webBuilder.UseStartup<Startup>();
15-
});
15+
var app = builder.Build();
1616

17-
public static void Main(string[] args)
17+
app.Use(async (context, next) =>
18+
{
19+
using var activity = new Activity("request");
20+
Activity.Current = activity;
21+
activity.Start();
22+
try
1823
{
19-
CreateHostBuilder(args).Build().Run();
24+
await next();
2025
}
26+
finally
27+
{
28+
activity.Stop();
29+
}
30+
});
31+
32+
app.UseResponseAutoWrapper();
2133

22-
#endregion Public 方法
34+
if (app.Environment.IsDevelopment())
35+
{
36+
app.MapOpenApi();
37+
app.MapSwaggerUI();
2338
}
39+
40+
app.UseRouting();
41+
42+
app.UseAuthorization();
43+
44+
app.MapControllers();
45+
46+
app.Run();

sample/CustomStructureWebApplication/Properties/launchSettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"profiles": {
33
"CustomStructureWebApplication": {
44
"commandName": "Project",
5-
"dotnetRunMessages": "true",
5+
"dotnetRunMessages": true,
66
"launchBrowser": true,
77
"launchUrl": "swagger",
8-
"applicationUrl": "http://localhost:5000",
8+
"applicationUrl": "http://localhost:5183",
99
"environmentVariables": {
1010
"ASPNETCORE_ENVIRONMENT": "Development"
1111
}

sample/CustomStructureWebApplication/Startup.cs

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,44 @@
1-
using Microsoft.AspNetCore.Hosting;
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.Extensions.DependencyInjection;
23
using Microsoft.Extensions.Hosting;
34

4-
namespace SimpleWebApplication;
5+
var builder = WebApplication.CreateBuilder(args);
56

6-
public class Program
7+
builder.Services.AddControllers();
8+
builder.Services.AddOpenApi();
9+
10+
//自动包装ActionResult
11+
builder.Services.AddResponseAutoWrapper(options =>
712
{
8-
#region Public 方法
13+
//配置
14+
//options.ActionNoWrapPredicate //Action的筛选委托,默认会过滤掉标记了NoResponseWrapAttribute的方法
15+
//options.DisableOpenAPISupport //禁用OpenAPI支持,Swagger将不会显示包装后的格式,也会解除响应类型必须为object泛型的限制
16+
//options.HandleAuthorizationResult //处理授权结果(可能无效,需要自行测试)
17+
//options.HandleInvalidModelState //处理无效模型状态
18+
//options.RewriteStatusCode = null; //包装时不覆写非200的HTTP状态码
19+
});
920

10-
public static IHostBuilder CreateHostBuilder(string[] args) =>
11-
Host.CreateDefaultBuilder(args)
12-
.ConfigureWebHostDefaults(webBuilder =>
13-
{
14-
webBuilder.UseStartup<Startup>();
15-
});
21+
var app = builder.Build();
1622

17-
public static void Main(string[] args)
18-
{
19-
CreateHostBuilder(args).Build().Run();
20-
}
23+
//捕获异常、非200状态码的请求,包装响应
24+
app.UseResponseAutoWrapper(options =>
25+
{
26+
//配置
27+
//options.CatchExceptions 是否捕获异常
28+
//options.ThrowCaughtExceptions 捕获到异常处理结束后,是否再将异常抛出
29+
//options.DefaultOutputFormatterSelector 默认输出格式化器选择委托,选择在请求中无 Accept 时,用于格式化响应的 IOutputFormatter
30+
});
2131

22-
#endregion Public 方法
32+
if (app.Environment.IsDevelopment())
33+
{
34+
app.MapOpenApi();
35+
app.MapSwaggerUI();
2336
}
37+
38+
app.UseRouting();
39+
40+
app.UseAuthorization();
41+
42+
app.MapControllers();
43+
44+
app.Run();

sample/SimpleWebApplication/Properties/launchSettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"profiles": {
33
"SimpleWebApplication": {
44
"commandName": "Project",
5-
"dotnetRunMessages": "true",
5+
"dotnetRunMessages": true,
66
"launchBrowser": true,
77
"launchUrl": "swagger",
8-
"applicationUrl": "http://localhost:5000",
8+
"applicationUrl": "http://localhost:5216",
99
"environmentVariables": {
1010
"ASPNETCORE_ENVIRONMENT": "Development"
1111
}

0 commit comments

Comments
 (0)