Skip to content

Commit d434098

Browse files
Update to .NET 8 (#653)
- Update to .NET 8. - Fix new code analysis warnings. - Use `UseArtifactsOutput=true` instead of explicitly setting the output path, as well as dropping explicit use of `--configuration` now that the default is `Release`. - Remove `Microsoft.SourceLink.GitHub` as it is now included in the .NET SDK. - Use `TimeProvider`. - Use primary constructors where relevant. - Use collection literals where relevant. - Apply some IDE suggestions. - Fix some typos. - Remove `CommonAssemblyInfo`. - Remove redundant suppressions. - Remove field with an array to use the `char` overload of `TrimEnd()` for .NET 6+ and an inline collection literal for .NET Standard 2.0. - Use the new MSBuild terminal logger. - Bump version to 3.3.0. - Bump Microsoft.Data.SqlClient to 5.1.2 for `net8.0`.
1 parent e502e85 commit d434098

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+187
-286
lines changed

.editorconfig

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ indent_style = space
99
insert_final_newline = true
1010
trim_trailing_whitespace = true
1111

12+
# Visual Studio Spell Checker
13+
spelling_exclusion_path = .\exclusion.dic
14+
spelling_languages = en-us
15+
1216
[*.{config,csproj,json,props,ruleset,targets,vsconfig,yml}]
1317
indent_size = 2
1418

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
- uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
5858
name: Upload coverage to Codecov
5959
with:
60-
file: ./artifacts/coverage/coverage.net7.0.cobertura.xml
60+
file: ./artifacts/coverage/coverage.net8.0.cobertura.xml
6161
flags: ${{ matrix.os_name }}
6262

6363
- name: Publish artifacts
@@ -70,7 +70,7 @@ jobs:
7070
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
7171
with:
7272
name: packages-${{ matrix.os_name }}
73-
path: ./artifacts/packages
73+
path: ./artifacts/package/release
7474
if-no-files-found: error
7575

7676
validate-packages:

.vsconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"components": [
44
"Microsoft.VisualStudio.Component.CoreEditor",
55
"Microsoft.VisualStudio.Workload.CoreEditor",
6-
"Microsoft.NetCore.Component.Runtime.7.0",
6+
"Microsoft.NetCore.Component.Runtime.8.0",
77
"Microsoft.NetCore.Component.SDK",
88
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
99
"Microsoft.VisualStudio.Component.Roslyn.LanguageServices"

CHANGELOG

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# CHANGELOG
22

3+
<!-- markdownlint-disable MD024 -->
4+
35
## SqlLocalDb v1.0.0.0
46

57
First release.
@@ -231,3 +233,9 @@ Added overloads to support specifying the name of the Initial Catalog using the
231233
### Added
232234

233235
* Fix incorrect minimum dependency versions when targeting `net6.0`.
236+
237+
## SqlLocalDb v3.3.0
238+
239+
### Added
240+
241+
* Add `net8.0` Target Framework Moniker.

Directory.Build.props

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
<NeutralLanguage>en-US</NeutralLanguage>
3232
<NoWarn>$(NoWarn);CA1054;CA1848;CA2234</NoWarn>
3333
<NoWarn Condition=" '$(GenerateDocumentationFile)' != 'true' ">$(NoWarn);SA0001</NoWarn>
34+
<!--
35+
HACK Workaround for https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3687
36+
-->
37+
<NoWarn>$(NoWarn);SA1010</NoWarn>
3438
<Nullable>enable</Nullable>
3539
<PackageIcon></PackageIcon>
3640
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
@@ -47,7 +51,8 @@
4751
<StrongNamePublicKey Condition=" '$(SignAssembly)' == 'true'">00240000048000009400000006020000002400005253413100040000010001004b0b2efbada897147aa03d2076278890aefe2f8023562336d206ec8a719b06e89461c31b43abec615918d509158629f93385930c030494509e418bf396d69ce7dbe0b5b2db1a81543ab42777cb98210677fed69dbeb3237492a7ad69e87a1911ed20eb2d7c300238dc6f6403e3d04a1351c5cb369de4e022b18fbec70f7d21ed</StrongNamePublicKey>
4852
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
4953
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
50-
<VersionPrefix>3.2.1</VersionPrefix>
54+
<UseArtifactsOutput>true</UseArtifactsOutput>
55+
<VersionPrefix>3.3.0</VersionPrefix>
5156
<VersionSuffix Condition=" '$(VersionSuffix)' == '' AND '$(GITHUB_ACTIONS)' != '' ">beta$([System.Convert]::ToInt32(`$(GITHUB_RUN_NUMBER)`).ToString(`0000`))</VersionSuffix>
5257
<VersionPrefix Condition=" $(GITHUB_REF.StartsWith(`refs/tags/v`)) ">$(GITHUB_REF.Replace('refs/tags/v', ''))</VersionPrefix>
5358
<VersionSuffix Condition=" $(GITHUB_REF.StartsWith(`refs/tags/v`)) "></VersionSuffix>

Directory.Build.targets

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
</ItemGroup>
2020
</Target>
2121
<PropertyGroup Condition=" '$(CollectCoverage)' == 'true' ">
22-
<CoverletOutput>$([System.IO.Path]::Combine($(OutputPath), 'coverage', 'coverage'))</CoverletOutput>
22+
<CoverletOutput>$([System.IO.Path]::Combine($(ArtifactsPath), 'coverage', 'coverage'))</CoverletOutput>
2323
<ReportGeneratorOutputMarkdown Condition=" '$(ReportGeneratorOutputMarkdown)' == '' AND '$(GITHUB_SHA)' != '' ">true</ReportGeneratorOutputMarkdown>
2424
<ReportGeneratorReportTypes>HTML</ReportGeneratorReportTypes>
2525
<ReportGeneratorReportTypes Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' ">$(ReportGeneratorReportTypes);MarkdownSummaryGitHub</ReportGeneratorReportTypes>
26-
<ReportGeneratorTargetDirectory>$([System.IO.Path]::Combine($(OutputPath), 'coverage'))</ReportGeneratorTargetDirectory>
26+
<ReportGeneratorTargetDirectory>$([System.IO.Path]::Combine($(ArtifactsPath), 'coverage'))</ReportGeneratorTargetDirectory>
2727
<_MarkdownSummaryPrefix>&lt;details&gt;&lt;summary&gt;:chart_with_upwards_trend: &lt;b&gt;$(AssemblyName) Code Coverage report&lt;/b&gt;&lt;/summary&gt;</_MarkdownSummaryPrefix>
2828
<_MarkdownSummarySuffix>&lt;/details&gt;</_MarkdownSummarySuffix>
2929
</PropertyGroup>

Directory.Packages.props

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
<Project>
2-
<PropertyGroup>
3-
<NodaTimeVersion>3.1.9</NodaTimeVersion>
4-
</PropertyGroup>
52
<ItemGroup>
63
<PackageVersion Include="coverlet.msbuild" Version="6.0.0" />
74
<PackageVersion Include="GitHubActionsTestLogger" Version="2.3.3" />
85
<PackageVersion Include="Humanizer" Version="2.14.1" />
96
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.3.0" />
107
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
11-
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.13" />
8+
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
9+
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="8.0.0" />
1210
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
13-
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
1411
<PackageVersion Include="NSubstitute" Version="5.1.0" />
15-
<PackageVersion Include="NodaTime" Version="$(NodaTimeVersion)" />
16-
<PackageVersion Include="NodaTime.Testing" Version="$(NodaTimeVersion)" />
1712
<PackageVersion Include="ReportGenerator" Version="5.1.26" />
1813
<PackageVersion Include="Shouldly" Version="4.2.1" />
1914
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.507" />
@@ -32,14 +27,18 @@
3227
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
3328
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
3429
</ItemGroup>
30+
<ItemGroup Condition=" '$(AssemblyName)' == 'MartinCostello.SqlLocalDb' and '$(TargetFramework)' == 'net8.0' ">
31+
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.2" />
32+
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
33+
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
34+
</ItemGroup>
3535
<ItemGroup Condition=" '$(AssemblyName)' != 'MartinCostello.SqlLocalDb' ">
3636
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.2" />
37-
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
38-
<PackageVersion Include="Microsoft.Extensions.Logging" Version="7.0.0" />
39-
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
37+
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
38+
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
39+
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
4040
</ItemGroup>
4141
<ItemGroup>
42-
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
4342
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" />
4443
</ItemGroup>
4544
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">

build.ps1

+3-22
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
#Requires -PSEdition Core
44
#Requires -Version 7
55

6-
param(
7-
[Parameter(Mandatory = $false)][string] $Configuration = "Release",
8-
[Parameter(Mandatory = $false)][string] $OutputPath = ""
9-
)
6+
param()
107

118
$env:DOTNET_MULTILEVEL_LOOKUP = "0"
129
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = "true"
@@ -29,10 +26,6 @@ $testProjects = @(
2926

3027
$dotnetVersion = (Get-Content $sdkFile | Out-String | ConvertFrom-Json).sdk.version
3128

32-
if ($OutputPath -eq "") {
33-
$OutputPath = (Join-Path $solutionPath "artifacts")
34-
}
35-
3629
$installDotNetSdk = $false;
3730

3831
if (($null -eq (Get-Command "dotnet" -ErrorAction SilentlyContinue)) -and ($null -eq (Get-Command "dotnet.exe" -ErrorAction SilentlyContinue))) {
@@ -90,14 +83,7 @@ if ($installDotNetSdk -eq $true) {
9083
function DotNetPack {
9184
param([string]$Project)
9285

93-
$PackageOutputPath = (Join-Path $OutputPath "packages")
94-
95-
& $dotnet pack `
96-
$Project `
97-
--output $PackageOutputPath `
98-
--configuration $Configuration `
99-
--include-source `
100-
--include-symbols
86+
& $dotnet pack $Project --include-source --include-symbols --tl
10187

10288
if ($LASTEXITCODE -ne 0) {
10389
throw "dotnet pack failed with exit code $LASTEXITCODE"
@@ -114,11 +100,7 @@ function DotNetTest {
114100
$additionalArgs += "GitHubActions;report-warnings=false"
115101
}
116102

117-
& $dotnet test `
118-
$Project `
119-
--output $OutputPath `
120-
--configuration $Configuration `
121-
$additionalArgs
103+
& $dotnet test $Project --configuration "Release" --tl $additionalArgs
122104

123105
if ($LASTEXITCODE -ne 0) {
124106
throw "dotnet test failed with exit code $LASTEXITCODE"
@@ -131,7 +113,6 @@ ForEach ($project in $packageProjects) {
131113
}
132114

133115
Write-Host "Testing $($testProjects.Count) project(s)..." -ForegroundColor Green
134-
Remove-Item -Path (Join-Path $OutputPath "coverage.*.json") -Force -ErrorAction SilentlyContinue | Out-Null
135116
ForEach ($project in $testProjects) {
136117
DotNetTest $project
137118
}

exclusion.dic

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
callback
2+
Unshare

global.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "7.0.403",
3+
"version": "8.0.100",
44
"allowPrerelease": false,
55
"rollForward": "latestMajor"
66
}

readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SQL LocalDB Wrapper
22

3-
SQL LocalDB Wrapper is a .NET library providing interop with the [Microsoft SQL Server LocalDB](https://docs.microsoft.com/en-us/sql/relational-databases/express-localdb-instance-apis/sql-server-express-localdb-reference-instance-apis?view=sql-server-2017 "SQL Server Express LocalDB Reference - Instance APIs") Instance API from managed code using .NET APIs. The library targets `netstandard2.0` and `net6.0`.
3+
SQL LocalDB Wrapper is a .NET library providing interop with the [Microsoft SQL Server LocalDB](https://docs.microsoft.com/en-us/sql/relational-databases/express-localdb-instance-apis/sql-server-express-localdb-reference-instance-apis?view=sql-server-2017 "SQL Server Express LocalDB Reference - Instance APIs") Instance API from managed code using .NET APIs. The library targets `netstandard2.0`, `net6.0` and `net8.0`.
44

55
[![NuGet](https://buildstats.info/nuget/MartinCostello.SqlLocalDb?includePreReleases=true)](https://www.nuget.org/packages/MartinCostello.SqlLocalDb "Download MartinCostello.SqlLocalDb from NuGet")
66

@@ -82,7 +82,7 @@ This project is licensed under the [Apache 2.0](http://www.apache.org/licenses/L
8282

8383
## Building and Testing
8484

85-
Compiling the library yourself requires Git and the [.NET SDK](https://www.microsoft.com/net/download/core "Download the .NET SDK") to be installed (version `7.0.100` or later).
85+
Compiling the library yourself requires Git and the [.NET SDK](https://www.microsoft.com/net/download/core "Download the .NET SDK") to be installed (version `8.0.100` or later).
8686

8787
For all of the tests to be functional you must also have at least one version of SQL LocalDB installed.
8888

samples/TodoApp.Tests/TodoApp.Tests.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<IsPackable>false</IsPackable>
4-
<NoWarn>$(NoWarn);CA1303;CA1707;CA2007;SA1600</NoWarn>
4+
<NoWarn>$(NoWarn);CA1303;CA1707;CA2007;EXTEXP0004;SA1600</NoWarn>
55
<RootNamespace>TodoApp</RootNamespace>
6-
<TargetFrameworks>net7.0</TargetFrameworks>
6+
<TargetFrameworks>net8.0</TargetFrameworks>
77
<IsPackable>false</IsPackable>
88
</PropertyGroup>
99
<ItemGroup>
1010
<FrameworkReference Include="Microsoft.AspNetCore.App" />
1111
<PackageReference Include="GitHubActionsTestLogger" />
1212
<PackageReference Include="MartinCostello.Logging.XUnit" />
13+
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" />
1314
<PackageReference Include="Microsoft.NET.Test.Sdk" />
14-
<PackageReference Include="NodaTime.Testing" />
1515
<PackageReference Include="Shouldly" />
1616
<PackageReference Include="xunit" />
1717
<PackageReference Include="xunit.runner.visualstudio" />

samples/TodoApp.Tests/TodoRepositoryTests.cs

+4-10
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,14 @@
44
using MartinCostello.SqlLocalDb;
55
using Microsoft.EntityFrameworkCore;
66
using Microsoft.Extensions.Logging;
7-
using NodaTime;
8-
using NodaTime.Testing;
7+
using Microsoft.Extensions.Time.Testing;
98
using TodoApp.Data;
109

1110
namespace TodoApp.Tests;
1211

13-
public class TodoRepositoryTests
12+
public class TodoRepositoryTests(ITestOutputHelper outputHelper)
1413
{
15-
public TodoRepositoryTests(ITestOutputHelper outputHelper)
16-
{
17-
LoggerFactory = outputHelper.ToLoggerFactory();
18-
}
19-
20-
private ILoggerFactory LoggerFactory { get; }
14+
private ILoggerFactory LoggerFactory { get; } = outputHelper.ToLoggerFactory();
2115

2216
[SkippableFact]
2317
public async Task Can_Create_Update_And_Delete_Todo_Items()
@@ -28,7 +22,7 @@ public async Task Can_Create_Update_And_Delete_Todo_Items()
2822
"This test can only be run on Windows.");
2923

3024
var now = new DateTimeOffset(2018, 08, 12, 10, 41, 0, TimeSpan.Zero);
31-
var clock = new FakeClock(Instant.FromDateTimeOffset(now));
25+
var clock = new FakeTimeProvider(now);
3226

3327
var options = new SqlLocalDbOptions()
3428
{

samples/TodoApp/Controllers/HomeController.cs

+6-15
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,12 @@
88

99
namespace TodoApp.Controllers;
1010

11-
public class HomeController : Controller
11+
public class HomeController(ITodoService service) : Controller
1212
{
13-
private readonly ITodoService _service;
14-
15-
public HomeController(ITodoService service)
16-
{
17-
_service = service;
18-
}
19-
2013
[HttpGet]
2114
public async Task<IActionResult> Index(CancellationToken cancellationToken = default)
2215
{
23-
TodoListViewModel model = await _service.GetListAsync(cancellationToken);
16+
TodoListViewModel model = await service.GetListAsync(cancellationToken);
2417
return View(model);
2518
}
2619

@@ -33,7 +26,7 @@ public async Task<IActionResult> AddItem(string text, CancellationToken cancella
3326
return BadRequest();
3427
}
3528

36-
await _service.AddItemAsync(text, cancellationToken);
29+
await service.AddItemAsync(text, cancellationToken);
3730

3831
return RedirectToAction(nameof(Index));
3932
}
@@ -47,7 +40,7 @@ public async Task<IActionResult> CompleteItem(string id, CancellationToken cance
4740
return BadRequest();
4841
}
4942

50-
bool? result = await _service.CompleteItemAsync(id, cancellationToken);
43+
bool? result = await service.CompleteItemAsync(id, cancellationToken);
5144

5245
if (result == null)
5346
{
@@ -71,7 +64,7 @@ public async Task<IActionResult> DeleteItem(string id, CancellationToken cancell
7164
return BadRequest();
7265
}
7366

74-
if (!await _service.DeleteItemAsync(id, cancellationToken))
67+
if (!await service.DeleteItemAsync(id, cancellationToken))
7568
{
7669
return NotFound();
7770
}
@@ -82,7 +75,5 @@ public async Task<IActionResult> DeleteItem(string id, CancellationToken cancell
8275
[HttpGet]
8376
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8477
public IActionResult Error()
85-
{
86-
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
87-
}
78+
=> View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
8879
}

samples/TodoApp/Data/TodoContext.cs

+5-10
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@ namespace TodoApp.Data;
88
/// <summary>
99
/// A class representing the database context for TodoApp.
1010
/// </summary>
11-
public class TodoContext : DbContext
11+
/// <remarks>
12+
/// Initializes a new instance of the <see cref="TodoContext"/> class.
13+
/// </remarks>
14+
/// <param name="options">The options for this context.</param>
15+
public class TodoContext(DbContextOptions<TodoContext> options) : DbContext(options)
1216
{
13-
/// <summary>
14-
/// Initializes a new instance of the <see cref="TodoContext"/> class.
15-
/// </summary>
16-
/// <param name="options">The options for this context.</param>
17-
public TodoContext(DbContextOptions<TodoContext> options)
18-
: base(options)
19-
{
20-
}
21-
2217
/// <summary>
2318
/// Gets or sets the database set containing the Todo items.
2419
/// </summary>

samples/TodoApp/Data/TodoInitializer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static class TodoInitializer
1616
/// <param name="serviceProvider">The <see cref="IServiceProvider"/> to use.</param>
1717
public static void Initialize(IServiceProvider serviceProvider)
1818
{
19-
using IServiceScope scope = serviceProvider.CreateScope();
19+
using var scope = serviceProvider.CreateScope();
2020

2121
var context = scope!.ServiceProvider!.GetService<TodoContext>();
2222
context!.Database.Migrate();

0 commit comments

Comments
 (0)