Skip to content

Commit 7596697

Browse files
authored
feat: support .NET 6 (#42)
* ci: use .NET 6 on CI * chore(deps): update .NET 6 libraries * build: add TargetFramework * style(csharp10): use File-scoped namespace * style(csharp10): use Global Using Directive * style: fix logging call (Analyzer suggestions) * chore(lint): use native dotnet-format tool * build: add ImplicitUsings option * chore: add .NET 6 benchmark
1 parent a4f72c1 commit 7596697

25 files changed

+3901
-855
lines changed

.config/dotnet-tools.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

.github/workflows/dotnetcore.yml

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: .NET Core CI
1+
name: .NET CI
22

33
on:
44
push:
@@ -22,50 +22,35 @@ jobs:
2222
runs-on: ubuntu-20.04
2323
steps:
2424
- uses: actions/checkout@v2
25-
- name: Setup .NET Core SDK
25+
- name: Setup .NET 6 SDK
2626
uses: actions/setup-dotnet@v1.8.2
27-
with:
28-
dotnet-version: 3.1
29-
- name: Restore Tool
30-
run: dotnet tool restore
3127
- name: Add Problem Matcher for dotnet-format
3228
uses: xt0rted/dotnet-format-problem-matcher@v1
3329
- name: Lint
34-
run: dotnet format --check
30+
run: dotnet format --verify-no-changes
3531

3632
test:
3733
strategy:
3834
fail-fast: false
3935
matrix:
40-
sdk-name:
41-
[".NET Core 3.1 (LTS)", ".NET 5 (Current)", ".NET 6 (Preview)"]
42-
include:
43-
- sdk-name: ".NET Core 3.1 (LTS)"
44-
sdk-version: 3.1.x
45-
- sdk-name: ".NET 5 (Current)"
46-
sdk-version: 5.0.x
47-
- sdk-name: ".NET 6 (Preview)"
48-
sdk-version: 6.0.x
36+
os: [ubuntu-latest, windows-latest, macos-latest]
4937
name: Debug Build & Test
50-
runs-on: ubuntu-20.04
38+
runs-on: ${{ matrix.os }}
5139
steps:
52-
- uses: actions/checkout@v2
40+
- uses: actions/checkout@v2.3.4
5341
- uses: actions/cache@v2.1.6
5442
with:
5543
path: ${{ env.NUGET_PACKAGES }}
5644
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
5745
restore-keys: |
5846
${{ runner.os }}-nuget-
47+
5948
- name: Setup .NET Core 3.1 SDK
60-
if: matrix.sdk-version != '3.1.x'
6149
uses: actions/setup-dotnet@v1.8.2
6250
with:
63-
dotnet-version: 3.1
64-
- name: Setup ${{ matrix.sdk-name }} SDK
51+
dotnet-version: 3.1.x
52+
- name: Setup .NET SDK
6553
uses: actions/setup-dotnet@v1.8.2
66-
with:
67-
dotnet-version: ${{ matrix.sdk-version }}
68-
include-prerelease: true
6954

7055
- name: Restore
7156
run: dotnet restore --locked-mode

.github/workflows/release.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@ env:
1313

1414
jobs:
1515
release:
16-
name: Release
16+
name: Publish to NuGet
1717
runs-on: ubuntu-20.04
1818
steps:
19-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v2.3.4
2020
- uses: actions/cache@v2.1.6
2121
with:
2222
path: ${{ env.NUGET_PACKAGES }}
2323
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
2424
restore-keys: |
2525
${{ runner.os }}-nuget-
2626
27-
- name: Setup .NET Core 3.1 SDK
27+
- name: Setup .NET 6 SDK
2828
uses: actions/setup-dotnet@v1.8.2
2929
with:
30-
dotnet-version: 3.1
30+
dotnet-version: 6.x
31+
include-prerelease: true
3132

3233
- name: Restore
3334
run: dotnet restore

Directory.Build.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
<!-- Build Options -->
1212
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
13-
<LangVersion>9.0</LangVersion>
13+
<LangVersion>10.0</LangVersion>
1414
<Nullable>enable</Nullable>
15+
<ImplicitUsings>enable</ImplicitUsings>
1516
</PropertyGroup>
1617
</Project>

global.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"sdk": {
3+
"version": "6.0.100",
4+
"rollForward": "latestFeature",
5+
"allowPrerelease": false
6+
}
7+
}

sandbox/Benchmark/Benchmark.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<TargetFrameworks>net6.0;netcoreapp3.1</TargetFrameworks>
66
<IsPackable>false</IsPackable>
7+
<ImplicitUsings>enable</ImplicitUsings>
78
</PropertyGroup>
89

910
<ItemGroup>
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1+
namespace Benchmark;
2+
13
using BenchmarkDotNet.Configs;
24
using BenchmarkDotNet.Environments;
35
using BenchmarkDotNet.Jobs;
46

5-
namespace Benchmark
7+
public class BenchmarkConfig : ManualConfig
68
{
7-
public class BenchmarkConfig : ManualConfig
9+
public BenchmarkConfig()
810
{
9-
public BenchmarkConfig()
10-
{
11-
AddJob(Job.Default.WithRuntime(CoreRuntime.Core31))
12-
.WithOptions(ConfigOptions.DisableOptimizationsValidator);
13-
AddJob(Job.Default.WithRuntime(CoreRuntime.Core50))
14-
.WithOptions(ConfigOptions.DisableOptimizationsValidator);
15-
}
11+
AddJob(Job.Default.WithRuntime(CoreRuntime.Core31))
12+
.WithOptions(ConfigOptions.DisableOptimizationsValidator);
13+
AddJob(Job.Default.WithRuntime(CoreRuntime.Core60))
14+
.WithOptions(ConfigOptions.DisableOptimizationsValidator);
1615
}
1716
}

sandbox/Benchmark/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Compare this project with [Awesome.Net.WritableOptions](https://www.nuget.org/pa
55
## How To
66

77
```console
8-
> dotnet run -c Release --filter *WritableOptionsBenchmark*
8+
> dotnet run -c Release -f net6.0 --filter *WritableOptionsBenchmark*
99
```
1010

1111
## Test Code
@@ -36,18 +36,18 @@ for (int i = 0; i < 1000; i++)
3636
``` ini
3737
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.18363.1139 (1909/November2019Update/19H2)
3838
AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx, 1 CPU, 8 logical and 4 physical cores
39-
.NET SDK=5.0.302
40-
[Host] : .NET Core 3.1.17 (CoreCLR 4.700.21.31506, CoreFX 4.700.21.31502), X64 RyuJIT
41-
Job-GUADFV : .NET 5.0.8 (5.0.821.31504), X64 RyuJIT
42-
Job-VCYLKU : .NET Core 3.1.17 (CoreCLR 4.700.21.31506, CoreFX 4.700.21.31502), X64 RyuJIT
39+
.NET SDK=6.0.100-rc.1.21458.32
40+
[Host] : .NET 6.0.0 (6.0.21.45113), X64 RyuJIT
41+
Job-IAUYRL : .NET 6.0.0 (6.0.21.45113), X64 RyuJIT
42+
Job-EAIPNX : .NET Core 3.1.17 (CoreCLR 4.700.21.31506, CoreFX 4.700.21.31502), X64 RyuJIT
4343

4444
InvocationCount=1 UnrollFactor=1
4545
```
4646

4747
| Method | Job | Runtime | Mean | Error | StdDev | Ratio | RatioSD |
4848
|------------------------------ |----------- |-------------- |--------:|---------:|---------:|------:|--------:|
49-
| AwesomeWritableOptions_Update | Job-GUADFV | .NET 5.0 | 4.530 s | 0.0873 s | 0.0971 s | 1.00 | 0.00 |
50-
| MyWritableOptions_Update | Job-GUADFV | .NET 5.0 | 3.756 s | 0.0513 s | 0.0480 s | 0.83 | 0.02 |
49+
| AwesomeWritableOptions_Update | Job-IAUYRL | .NET 6.0 | 4.125 s | 0.0784 s | 0.0695 s | 1.00 | 0.00 |
50+
| MyWritableOptions_Update | Job-IAUYRL | .NET 6.0 | 3.369 s | 0.0673 s | 0.1162 s | 0.82 | 0.04 |
5151
| | | | | | | | |
52-
| AwesomeWritableOptions_Update | Job-VCYLKU | .NET Core 3.1 | 4.644 s | 0.0862 s | 0.0764 s | 1.00 | 0.00 |
53-
| MyWritableOptions_Update | Job-VCYLKU | .NET Core 3.1 | 3.930 s | 0.0781 s | 0.0836 s | 0.85 | 0.02 |
52+
| AwesomeWritableOptions_Update | Job-EAIPNX | .NET Core 3.1 | 4.167 s | 0.0829 s | 0.1106 s | 1.00 | 0.00 |
53+
| MyWritableOptions_Update | Job-EAIPNX | .NET Core 3.1 | 3.497 s | 0.0687 s | 0.1221 s | 0.84 | 0.04 |
Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,68 @@
11
#nullable disable
2-
using System;
2+
namespace Benchmark;
3+
34
using System.IO;
4-
using System.Linq;
55
using BenchmarkDotNet.Attributes;
66

7-
namespace Benchmark
7+
[Config(typeof(BenchmarkConfig))]
8+
public class WritableOptionsBenchmark
89
{
9-
[Config(typeof(BenchmarkConfig))]
10-
public class WritableOptionsBenchmark
10+
public class SampleOption
1111
{
12-
public class SampleOption
13-
{
14-
public DateTime LastLaunchedAt { get; set; }
15-
public string[] StringSettings { get; set; }
16-
public int[] IntSettings { get; set; }
17-
}
12+
public DateTime LastLaunchedAt { get; set; }
13+
public string[] StringSettings { get; set; }
14+
public int[] IntSettings { get; set; }
15+
}
1816

19-
private Awesome.Net.WritableOptions.WritableOptions<SampleOption> _awesomeWritableOptions;
20-
private Nogic.WritableOptions.JsonWritableOptions<SampleOption> _myWritableOptions;
21-
private SampleOption _option;
22-
private string _jsonFilePath;
17+
private Awesome.Net.WritableOptions.WritableOptions<SampleOption> _awesomeWritableOptions;
18+
private Nogic.WritableOptions.JsonWritableOptions<SampleOption> _myWritableOptions;
19+
private SampleOption _option;
20+
private string _jsonFilePath;
2321

24-
[GlobalSetup]
25-
public void GlobalSetup() => _option = new()
26-
{
27-
LastLaunchedAt = DateTime.Now,
28-
StringSettings = Enumerable.Range(1, 100).Select((_) => Guid.NewGuid().ToString()).ToArray(),
29-
IntSettings = Enumerable.Range(1, 100).ToArray()
30-
};
22+
[GlobalSetup]
23+
public void GlobalSetup() => _option = new()
24+
{
25+
LastLaunchedAt = DateTime.Now,
26+
StringSettings = Enumerable.Range(1, 100).Select((_) => Guid.NewGuid().ToString()).ToArray(),
27+
IntSettings = Enumerable.Range(1, 100).ToArray()
28+
};
3129

32-
[IterationSetup]
33-
public void ItarationSetup()
34-
{
35-
_jsonFilePath = Path.GetTempFileName();
36-
File.AppendAllText(_jsonFilePath, "{}");
37-
_awesomeWritableOptions = new(_jsonFilePath, nameof(SampleOption), null!, null);
38-
_myWritableOptions = new(_jsonFilePath, nameof(SampleOption), null!, null);
39-
}
30+
[IterationSetup]
31+
public void ItarationSetup()
32+
{
33+
_jsonFilePath = Path.GetTempFileName();
34+
File.AppendAllText(_jsonFilePath, "{}");
35+
_awesomeWritableOptions = new(_jsonFilePath, nameof(SampleOption), null!, null);
36+
_myWritableOptions = new(_jsonFilePath, nameof(SampleOption), null!, null);
37+
}
4038

41-
[Benchmark(Baseline = true)]
42-
public void AwesomeWritableOptions_Update()
39+
[Benchmark(Baseline = true)]
40+
public void AwesomeWritableOptions_Update()
41+
{
42+
for (int i = 0; i < 1000; i++)
4343
{
44-
for (int i = 0; i < 1000; i++)
44+
_awesomeWritableOptions.Update(o =>
4545
{
46-
_awesomeWritableOptions.Update(o =>
47-
{
48-
o.LastLaunchedAt = _option.LastLaunchedAt;
49-
o.StringSettings = _option.StringSettings;
50-
o.IntSettings = _option.IntSettings;
51-
});
52-
}
46+
o.LastLaunchedAt = _option.LastLaunchedAt;
47+
o.StringSettings = _option.StringSettings;
48+
o.IntSettings = _option.IntSettings;
49+
});
5350
}
51+
}
5452

55-
[Benchmark]
56-
public void MyWritableOptions_Update()
53+
[Benchmark]
54+
public void MyWritableOptions_Update()
55+
{
56+
for (int i = 0; i < 1000; i++)
5757
{
58-
for (int i = 0; i < 1000; i++)
59-
{
60-
_myWritableOptions.Update(_option);
61-
}
58+
_myWritableOptions.Update(_option);
6259
}
60+
}
6361

64-
[IterationCleanup]
65-
public void Teardown()
66-
{
67-
if (File.Exists(_jsonFilePath))
68-
File.Delete(_jsonFilePath);
69-
}
62+
[IterationCleanup]
63+
public void Teardown()
64+
{
65+
if (File.Exists(_jsonFilePath))
66+
File.Delete(_jsonFilePath);
7067
}
7168
}

0 commit comments

Comments
 (0)