From 743e04a0bdfe17be6ee016e03cbbdaae89d8b603 Mon Sep 17 00:00:00 2001 From: Craig Treasure Date: Sat, 16 Nov 2024 18:09:05 -0800 Subject: [PATCH] Update to .NET This change updates the project to .NET 9 and removes support for .NET 6. I've also removed the benchmarks project as it's really not necessary. --- .github/actions/install-tools/action.yml | 3 +- Treasure.Utils.sln | 7 -- eng/DotNetAnalyzers.props | 2 +- eng/DotNetDefaults.props | 2 +- global.json | 2 +- .../Treasure.Utils.Argument.csproj | 2 +- test/Directory.Build.props | 2 +- .../Combine.ps1 | 107 ----------------- .../Program.cs | 108 ------------------ .../Run.ps1 | 25 ---- .../Treasure.Utils.Argument.Benchmarks.csproj | 25 ---- .../Treasure.Utils.Argument.Tests.csproj | 2 +- 12 files changed, 7 insertions(+), 280 deletions(-) delete mode 100644 test/Treasure.Utils.Argument.Benchmarks/Combine.ps1 delete mode 100644 test/Treasure.Utils.Argument.Benchmarks/Program.cs delete mode 100644 test/Treasure.Utils.Argument.Benchmarks/Run.ps1 delete mode 100644 test/Treasure.Utils.Argument.Benchmarks/Treasure.Utils.Argument.Benchmarks.csproj diff --git a/.github/actions/install-tools/action.yml b/.github/actions/install-tools/action.yml index 3d56292..789a7cc 100644 --- a/.github/actions/install-tools/action.yml +++ b/.github/actions/install-tools/action.yml @@ -7,9 +7,8 @@ runs: uses: actions/setup-dotnet@v3 with: dotnet-version: | - 6.x - 7.x 8.x + 9.x - name: Install .NET tools shell: pwsh diff --git a/Treasure.Utils.sln b/Treasure.Utils.sln index da0dec0..5b53e04 100644 --- a/Treasure.Utils.sln +++ b/Treasure.Utils.sln @@ -22,8 +22,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution version.json = version.json EndProjectSection EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Treasure.Utils.Argument.Benchmarks", "test\Treasure.Utils.Argument.Benchmarks\Treasure.Utils.Argument.Benchmarks.csproj", "{AB3B36BF-791F-4DC2-8B53-4BA812A80E86}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7C628D75-6B6A-4D42-A4D9-45C6ACA51FB5}" ProjectSection(SolutionItems) = preProject src\Directory.Packages.props = src\Directory.Packages.props @@ -50,17 +48,12 @@ Global {EF141707-718F-49EC-99B9-8D7B59CBCCEF}.Debug|Any CPU.Build.0 = Debug|Any CPU {EF141707-718F-49EC-99B9-8D7B59CBCCEF}.Release|Any CPU.ActiveCfg = Release|Any CPU {EF141707-718F-49EC-99B9-8D7B59CBCCEF}.Release|Any CPU.Build.0 = Release|Any CPU - {AB3B36BF-791F-4DC2-8B53-4BA812A80E86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {AB3B36BF-791F-4DC2-8B53-4BA812A80E86}.Debug|Any CPU.Build.0 = Debug|Any CPU - {AB3B36BF-791F-4DC2-8B53-4BA812A80E86}.Release|Any CPU.ActiveCfg = Release|Any CPU - {AB3B36BF-791F-4DC2-8B53-4BA812A80E86}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {EF141707-718F-49EC-99B9-8D7B59CBCCEF} = {B012001D-4B86-460D-A3E1-FC3EEC840D13} - {AB3B36BF-791F-4DC2-8B53-4BA812A80E86} = {B012001D-4B86-460D-A3E1-FC3EEC840D13} {7C628D75-6B6A-4D42-A4D9-45C6ACA51FB5} = {A18B8F8E-8296-4968-A569-16F3F4FE045E} {61D20241-7C98-4A60-AA8D-C7614B7D6768} = {A18B8F8E-8296-4968-A569-16F3F4FE045E} EndGlobalSection diff --git a/eng/DotNetAnalyzers.props b/eng/DotNetAnalyzers.props index 10191c6..bf696f7 100644 --- a/eng/DotNetAnalyzers.props +++ b/eng/DotNetAnalyzers.props @@ -7,7 +7,7 @@ true AllEnabledByDefault true - 8.0 + 9.0 diff --git a/eng/DotNetDefaults.props b/eng/DotNetDefaults.props index 6bf86fd..f2ae552 100644 --- a/eng/DotNetDefaults.props +++ b/eng/DotNetDefaults.props @@ -10,7 +10,7 @@ - 12.0 + latest -windows - net6.0$(PlatformTFMSuffix) + net8.0$(PlatformTFMSuffix) diff --git a/test/Treasure.Utils.Argument.Benchmarks/Combine.ps1 b/test/Treasure.Utils.Argument.Benchmarks/Combine.ps1 deleted file mode 100644 index 9fb544b..0000000 --- a/test/Treasure.Utils.Argument.Benchmarks/Combine.ps1 +++ /dev/null @@ -1,107 +0,0 @@ -#Requires -PSEdition Core - -[CmdletBinding()] -Param ( - [string[]] $TFMs = @('net6.0', 'net6.0-windows', 'net8.0', 'net8.0-windows'), - [string[]] $Columns = @( 'Runtime', 'TFM', 'LibraryTfm', 'Method', 'Mean', 'Error', 'StdDev', 'Code Size'), - [string] $ArtifactInputRoot = (Join-Path $PSScriptRoot '..' '..' '__benchmarks'), - [string] $ResultOutputPath = (Join-Path $PSScriptRoot '..' '..' '__benchmarks' 'results.md'), - [string[]] $MethodSortOrder = @( - 'ArgumentNotNull', - 'ArgumentNullExceptionThrowIfNull', - 'IfValueIsNullThrowArgumentNullException', - 'ArgumentNotNullOrEmpty', - 'ArgumentExceptionThrowIfNullOrEmpty', - 'IfValueIsNullOrEmptyThrowArgumentException', - 'ArgumentNotNullOrWhiteSpace', - 'ArgumentExceptionThrowIfNullOrWhiteSpace', - 'IfValueIsNullOrWhiteSpaceThrowArgumentException') -) - -$ErrorActionPreference = 'Stop' -Set-StrictMode -Version 2 - -function BuildTableRowFromData ($rowData) { - $row = '|' - - foreach ($data in $rowData) { - $row += " $data |" - } - - return $row -} - -function BuildTableRowFromColumnsAndData ($columns, $data) { - BuildTableRowFromData ($columns | ForEach-Object { $data.$_ }) -} - -function GetLibraryTfmName ($tfm) { - if ($tfm -eq 'net6.0') { - return 'net6.0' - } - - if ($tfm -eq 'net8.0') { - return 'net8.0' - } - - if ($tfm.Contains('-')) { - return 'netstandard2.1' - } - - throw "Unknown TFM '$tfm'." -} - -function GetLibraryTfmValue ($data, $libraryTfm) { - if ($data.Method.Contains('Exception')) { - return 'NA' - } - - return $libraryTfm -} - -if (!(Test-Path $ArtifactInputRoot)) { - Write-Error "Artifact input root path '$ArtifactInputRoot' does not exist." -} - -$csvData = @() -$TFMs - | ForEach-Object { - [PSCustomObject] @{ - libraryTfm = (GetLibraryTfmName $_) - tfm = $_ - path = (Join-Path $ArtifactInputRoot "$_.artifacts/results/Tests-report.csv") - } - } - | Where-Object { Test-Path $_.path } - | ForEach-Object { - $libraryTfm = $_.libraryTfm - $tfm = $_.tfm - Import-Csv -Path $_.path - | ForEach-Object { - $_ | Add-Member -NotePropertyName 'LibraryTfm' -NotePropertyValue (GetLibraryTfmValue $_ $libraryTfm) -PassThru - | Add-Member -NotePropertyName 'TFM' -NotePropertyValue $tfm -PassThru - } - } - | ForEach-Object { $csvData += $_ } -$csvData = $csvData | Sort-Object { $MethodSortOrder.IndexOf($_.Method) }, Runtime, LibraryTfm, TFM - -# Write header to markdown file -Set-Content -Path $ResultOutputPath -Value '# Results' -Add-Content -Path $ResultOutputPath -Value '' -Add-Content -Path $ResultOutputPath -Value (BuildTableRowFromData $Columns) -Add-Content -Path $ResultOutputPath -Value (BuildTableRowFromData ($Columns | ForEach-Object { '-'*$_.Length })) - -# Write to markdown file -$emptyRow = BuildTableRowFromData ($Columns | ForEach-Object { '' } ) -$lastMethod = $csvData[0].Method -$csvData | ForEach-Object { - $method = $_.Method - - if ($method -ne $lastMethod) { - Add-Content -Path $ResultOutputPath -Value $emptyRow - $lastMethod = $method - } - - $mdLine = BuildTableRowFromColumnsAndData $Columns $_ - Add-Content -Path $ResultOutputPath -Value $mdLine -} diff --git a/test/Treasure.Utils.Argument.Benchmarks/Program.cs b/test/Treasure.Utils.Argument.Benchmarks/Program.cs deleted file mode 100644 index b0b1791..0000000 --- a/test/Treasure.Utils.Argument.Benchmarks/Program.cs +++ /dev/null @@ -1,108 +0,0 @@ -// .\Run.ps1 -// or -// dotnet run -c Release -f [net6.0 net8.0] --filter "*" - -#pragma warning disable CA1050 -#pragma warning disable CA1812 -#pragma warning disable CA1822 -#pragma warning disable CA1510 -#pragma warning disable CS1591 -#pragma warning disable IDE0211 - -using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Running; - -using Treasure.Utils; - -BenchmarkRunner.Run(args: args); - -[HideColumns("value")] -[DisassemblyDiagnoser] -public class Tests -{ - [Benchmark] - [Arguments("foo")] - public void ArgumentNotNull(string? value) - { - Argument.NotNull(value); - } - - [Benchmark] - [Arguments("foo")] - public void ArgumentNullExceptionThrowIfNull(string? value) - { - ArgumentNullException.ThrowIfNull(value); - } - - [Benchmark] - [Arguments("foo")] - public void IfValueIsNullThrowArgumentNullException(string? value) - { - if (value is null) - { - throw new ArgumentNullException(nameof(value)); - } - } - - [Benchmark] - [Arguments("foo")] - public void ArgumentNotNullOrEmpty(string? value) - { - Argument.NotNullOrEmpty(value); - } - -#if NET7_0_OR_GREATER - [Benchmark] - [Arguments("foo")] - public void ArgumentExceptionThrowIfNullOrEmpty(string? value) - { - ArgumentException.ThrowIfNullOrEmpty(value); - } -#endif - - [Benchmark] - [Arguments("foo")] - public void IfValueIsNullOrEmptyThrowArgumentException(string? value) - { - if (value is null) - { - throw new ArgumentNullException(value); - } - - if (string.IsNullOrEmpty(value)) - { - throw new ArgumentException("Value cannot be null or empty.", nameof(value)); - } - } - - [Benchmark] - [Arguments("foo")] - public void ArgumentNotNullOrWhiteSpace(string? value) - { - Argument.NotNullOrWhiteSpace(value); - } - -#if NET8_0_OR_GREATER - [Benchmark] - [Arguments("foo")] - public void ArgumentExceptionThrowIfNullOrWhiteSpace(string? value) - { - ArgumentException.ThrowIfNullOrWhiteSpace(value); - } -#endif - - [Benchmark] - [Arguments("foo")] - public void IfValueIsNullOrWhiteSpaceThrowArgumentException(string? value) - { - if (value is null) - { - throw new ArgumentNullException(value); - } - - if (string.IsNullOrWhiteSpace(value)) - { - throw new ArgumentException("Value cannot be null or empty.", nameof(value)); - } - } -} diff --git a/test/Treasure.Utils.Argument.Benchmarks/Run.ps1 b/test/Treasure.Utils.Argument.Benchmarks/Run.ps1 deleted file mode 100644 index c26d63d..0000000 --- a/test/Treasure.Utils.Argument.Benchmarks/Run.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -#Requires -PSEdition Core - -[CmdletBinding()] -Param ( - [string[]] $TFMs = @('net6.0', 'net6.0-windows', 'net8.0', 'net8.0-windows'), - [string] $ArtifactOutputRoot = (Join-Path $PSScriptRoot '..' '..' '__benchmarks'), - [string] $ResultOutputPath = (Join-Path $PSScriptRoot '..' '..' '__benchmarks' 'results.md') -) - -$ErrorActionPreference = 'Stop' -Set-StrictMode -Version 2 - -Push-Location $PSScriptRoot -try { - foreach ($tfm in $TFMs) { - $tfmBenchmarkOutput = Join-Path $ArtifactOutputRoot "$tfm.artifacts" - dotnet run -c Release -f $tfm --filter "*" -- -a $tfmBenchmarkOutput - } -} -finally { - Pop-Location -} - -$combineScriptPath = Join-Path $PSScriptRoot 'Combine.ps1' -. $combineScriptPath -TFMs $TFMs -ArtifactInputRoot $ArtifactOutputRoot -ResultOutputPath $ResultOutputPath diff --git a/test/Treasure.Utils.Argument.Benchmarks/Treasure.Utils.Argument.Benchmarks.csproj b/test/Treasure.Utils.Argument.Benchmarks/Treasure.Utils.Argument.Benchmarks.csproj deleted file mode 100644 index 9bea124..0000000 --- a/test/Treasure.Utils.Argument.Benchmarks/Treasure.Utils.Argument.Benchmarks.csproj +++ /dev/null @@ -1,25 +0,0 @@ - - - - Exe - net8.0;net6.0 - $(TargetFrameworks);net8.0$(PlatformTFMSuffix);net6.0$(PlatformTFMSuffix) - Treasure.Utils.Benchmarks - false - - true - true - - - - - - - - - - - - diff --git a/test/Treasure.Utils.Argument.Tests/Treasure.Utils.Argument.Tests.csproj b/test/Treasure.Utils.Argument.Tests/Treasure.Utils.Argument.Tests.csproj index 2035273..e73f15f 100644 --- a/test/Treasure.Utils.Argument.Tests/Treasure.Utils.Argument.Tests.csproj +++ b/test/Treasure.Utils.Argument.Tests/Treasure.Utils.Argument.Tests.csproj @@ -1,7 +1,7 @@ - net8.0;net6.0 + net9.0;net8.0 $(TargetFrameworks);$(DefaultNetStandardTestTFM) Treasure.Utils.Tests