Skip to content

Commit

Permalink
Update to .NET 8 (#653)
Browse files Browse the repository at this point in the history
- 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`.
  • Loading branch information
martincostello authored Nov 14, 2023
1 parent e502e85 commit d434098
Show file tree
Hide file tree
Showing 47 changed files with 187 additions and 286 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

# Visual Studio Spell Checker
spelling_exclusion_path = .\exclusion.dic
spelling_languages = en-us

[*.{config,csproj,json,props,ruleset,targets,vsconfig,yml}]
indent_size = 2

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
name: Upload coverage to Codecov
with:
file: ./artifacts/coverage/coverage.net7.0.cobertura.xml
file: ./artifacts/coverage/coverage.net8.0.cobertura.xml
flags: ${{ matrix.os_name }}

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

validate-packages:
Expand Down
2 changes: 1 addition & 1 deletion .vsconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"components": [
"Microsoft.VisualStudio.Component.CoreEditor",
"Microsoft.VisualStudio.Workload.CoreEditor",
"Microsoft.NetCore.Component.Runtime.7.0",
"Microsoft.NetCore.Component.Runtime.8.0",
"Microsoft.NetCore.Component.SDK",
"Microsoft.VisualStudio.Component.Roslyn.Compiler",
"Microsoft.VisualStudio.Component.Roslyn.LanguageServices"
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# CHANGELOG

<!-- markdownlint-disable MD024 -->

## SqlLocalDb v1.0.0.0

First release.
Expand Down Expand Up @@ -231,3 +233,9 @@ Added overloads to support specifying the name of the Initial Catalog using the
### Added

* Fix incorrect minimum dependency versions when targeting `net6.0`.

## SqlLocalDb v3.3.0

### Added

* Add `net8.0` Target Framework Moniker.
7 changes: 6 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<NeutralLanguage>en-US</NeutralLanguage>
<NoWarn>$(NoWarn);CA1054;CA1848;CA2234</NoWarn>
<NoWarn Condition=" '$(GenerateDocumentationFile)' != 'true' ">$(NoWarn);SA0001</NoWarn>
<!--
HACK Workaround for https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3687
-->
<NoWarn>$(NoWarn);SA1010</NoWarn>
<Nullable>enable</Nullable>
<PackageIcon></PackageIcon>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
Expand All @@ -47,7 +51,8 @@
<StrongNamePublicKey Condition=" '$(SignAssembly)' == 'true'">00240000048000009400000006020000002400005253413100040000010001004b0b2efbada897147aa03d2076278890aefe2f8023562336d206ec8a719b06e89461c31b43abec615918d509158629f93385930c030494509e418bf396d69ce7dbe0b5b2db1a81543ab42777cb98210677fed69dbeb3237492a7ad69e87a1911ed20eb2d7c300238dc6f6403e3d04a1351c5cb369de4e022b18fbec70f7d21ed</StrongNamePublicKey>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<VersionPrefix>3.2.1</VersionPrefix>
<UseArtifactsOutput>true</UseArtifactsOutput>
<VersionPrefix>3.3.0</VersionPrefix>
<VersionSuffix Condition=" '$(VersionSuffix)' == '' AND '$(GITHUB_ACTIONS)' != '' ">beta$([System.Convert]::ToInt32(`$(GITHUB_RUN_NUMBER)`).ToString(`0000`))</VersionSuffix>
<VersionPrefix Condition=" $(GITHUB_REF.StartsWith(`refs/tags/v`)) ">$(GITHUB_REF.Replace('refs/tags/v', ''))</VersionPrefix>
<VersionSuffix Condition=" $(GITHUB_REF.StartsWith(`refs/tags/v`)) "></VersionSuffix>
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
</ItemGroup>
</Target>
<PropertyGroup Condition=" '$(CollectCoverage)' == 'true' ">
<CoverletOutput>$([System.IO.Path]::Combine($(OutputPath), 'coverage', 'coverage'))</CoverletOutput>
<CoverletOutput>$([System.IO.Path]::Combine($(ArtifactsPath), 'coverage', 'coverage'))</CoverletOutput>
<ReportGeneratorOutputMarkdown Condition=" '$(ReportGeneratorOutputMarkdown)' == '' AND '$(GITHUB_SHA)' != '' ">true</ReportGeneratorOutputMarkdown>
<ReportGeneratorReportTypes>HTML</ReportGeneratorReportTypes>
<ReportGeneratorReportTypes Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' ">$(ReportGeneratorReportTypes);MarkdownSummaryGitHub</ReportGeneratorReportTypes>
<ReportGeneratorTargetDirectory>$([System.IO.Path]::Combine($(OutputPath), 'coverage'))</ReportGeneratorTargetDirectory>
<ReportGeneratorTargetDirectory>$([System.IO.Path]::Combine($(ArtifactsPath), 'coverage'))</ReportGeneratorTargetDirectory>
<_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>
<_MarkdownSummarySuffix>&lt;/details&gt;</_MarkdownSummarySuffix>
</PropertyGroup>
Expand Down
21 changes: 10 additions & 11 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
<Project>
<PropertyGroup>
<NodaTimeVersion>3.1.9</NodaTimeVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="coverlet.msbuild" Version="6.0.0" />
<PackageVersion Include="GitHubActionsTestLogger" Version="2.3.3" />
<PackageVersion Include="Humanizer" Version="2.14.1" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.3.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.13" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.TimeProvider.Testing" Version="8.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
<PackageVersion Include="NodaTime" Version="$(NodaTimeVersion)" />
<PackageVersion Include="NodaTime.Testing" Version="$(NodaTimeVersion)" />
<PackageVersion Include="ReportGenerator" Version="5.1.26" />
<PackageVersion Include="Shouldly" Version="4.2.1" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.507" />
Expand All @@ -32,14 +27,18 @@
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(AssemblyName)' == 'MartinCostello.SqlLocalDb' and '$(TargetFramework)' == 'net8.0' ">
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(AssemblyName)' != 'MartinCostello.SqlLocalDb' ">
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
Expand Down
25 changes: 3 additions & 22 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
#Requires -PSEdition Core
#Requires -Version 7

param(
[Parameter(Mandatory = $false)][string] $Configuration = "Release",
[Parameter(Mandatory = $false)][string] $OutputPath = ""
)
param()

$env:DOTNET_MULTILEVEL_LOOKUP = "0"
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = "true"
Expand All @@ -29,10 +26,6 @@ $testProjects = @(

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

if ($OutputPath -eq "") {
$OutputPath = (Join-Path $solutionPath "artifacts")
}

$installDotNetSdk = $false;

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

$PackageOutputPath = (Join-Path $OutputPath "packages")

& $dotnet pack `
$Project `
--output $PackageOutputPath `
--configuration $Configuration `
--include-source `
--include-symbols
& $dotnet pack $Project --include-source --include-symbols --tl

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

& $dotnet test `
$Project `
--output $OutputPath `
--configuration $Configuration `
$additionalArgs
& $dotnet test $Project --configuration "Release" --tl $additionalArgs

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

Write-Host "Testing $($testProjects.Count) project(s)..." -ForegroundColor Green
Remove-Item -Path (Join-Path $OutputPath "coverage.*.json") -Force -ErrorAction SilentlyContinue | Out-Null
ForEach ($project in $testProjects) {
DotNetTest $project
}
2 changes: 2 additions & 0 deletions exclusion.dic
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
callback
Unshare
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.403",
"version": "8.0.100",
"allowPrerelease": false,
"rollForward": "latestMajor"
}
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SQL LocalDB Wrapper

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`.
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`.

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

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

## Building and Testing

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).
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).

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

Expand Down
6 changes: 3 additions & 3 deletions samples/TodoApp.Tests/TodoApp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);CA1303;CA1707;CA2007;SA1600</NoWarn>
<NoWarn>$(NoWarn);CA1303;CA1707;CA2007;EXTEXP0004;SA1600</NoWarn>
<RootNamespace>TodoApp</RootNamespace>
<TargetFrameworks>net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="GitHubActionsTestLogger" />
<PackageReference Include="MartinCostello.Logging.XUnit" />
<PackageReference Include="Microsoft.Extensions.TimeProvider.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NodaTime.Testing" />
<PackageReference Include="Shouldly" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
Expand Down
14 changes: 4 additions & 10 deletions samples/TodoApp.Tests/TodoRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
using MartinCostello.SqlLocalDb;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using NodaTime;
using NodaTime.Testing;
using Microsoft.Extensions.Time.Testing;
using TodoApp.Data;

namespace TodoApp.Tests;

public class TodoRepositoryTests
public class TodoRepositoryTests(ITestOutputHelper outputHelper)
{
public TodoRepositoryTests(ITestOutputHelper outputHelper)
{
LoggerFactory = outputHelper.ToLoggerFactory();
}

private ILoggerFactory LoggerFactory { get; }
private ILoggerFactory LoggerFactory { get; } = outputHelper.ToLoggerFactory();

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

var now = new DateTimeOffset(2018, 08, 12, 10, 41, 0, TimeSpan.Zero);
var clock = new FakeClock(Instant.FromDateTimeOffset(now));
var clock = new FakeTimeProvider(now);

var options = new SqlLocalDbOptions()
{
Expand Down
21 changes: 6 additions & 15 deletions samples/TodoApp/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,12 @@

namespace TodoApp.Controllers;

public class HomeController : Controller
public class HomeController(ITodoService service) : Controller
{
private readonly ITodoService _service;

public HomeController(ITodoService service)
{
_service = service;
}

[HttpGet]
public async Task<IActionResult> Index(CancellationToken cancellationToken = default)
{
TodoListViewModel model = await _service.GetListAsync(cancellationToken);
TodoListViewModel model = await service.GetListAsync(cancellationToken);
return View(model);
}

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

await _service.AddItemAsync(text, cancellationToken);
await service.AddItemAsync(text, cancellationToken);

return RedirectToAction(nameof(Index));
}
Expand All @@ -47,7 +40,7 @@ public async Task<IActionResult> CompleteItem(string id, CancellationToken cance
return BadRequest();
}

bool? result = await _service.CompleteItemAsync(id, cancellationToken);
bool? result = await service.CompleteItemAsync(id, cancellationToken);

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

if (!await _service.DeleteItemAsync(id, cancellationToken))
if (!await service.DeleteItemAsync(id, cancellationToken))
{
return NotFound();
}
Expand All @@ -82,7 +75,5 @@ public async Task<IActionResult> DeleteItem(string id, CancellationToken cancell
[HttpGet]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
=> View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
15 changes: 5 additions & 10 deletions samples/TodoApp/Data/TodoContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@ namespace TodoApp.Data;
/// <summary>
/// A class representing the database context for TodoApp.
/// </summary>
public class TodoContext : DbContext
/// <remarks>
/// Initializes a new instance of the <see cref="TodoContext"/> class.
/// </remarks>
/// <param name="options">The options for this context.</param>
public class TodoContext(DbContextOptions<TodoContext> options) : DbContext(options)
{
/// <summary>
/// Initializes a new instance of the <see cref="TodoContext"/> class.
/// </summary>
/// <param name="options">The options for this context.</param>
public TodoContext(DbContextOptions<TodoContext> options)
: base(options)
{
}

/// <summary>
/// Gets or sets the database set containing the Todo items.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion samples/TodoApp/Data/TodoInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class TodoInitializer
/// <param name="serviceProvider">The <see cref="IServiceProvider"/> to use.</param>
public static void Initialize(IServiceProvider serviceProvider)
{
using IServiceScope scope = serviceProvider.CreateScope();
using var scope = serviceProvider.CreateScope();

var context = scope!.ServiceProvider!.GetService<TodoContext>();
context!.Database.Migrate();
Expand Down
Loading

0 comments on commit d434098

Please sign in to comment.