Skip to content

Commit

Permalink
Add support for .NET 8
Browse files Browse the repository at this point in the history
This change adds support for .NET 8. Unlike similar PRs in my other repos, it does not enable artifacts support yet due to an issue with [benchmarkdotnet](dotnet/BenchmarkDotNet#2466).
  • Loading branch information
craigktreasure committed Nov 17, 2023
1 parent 2379fbb commit f489b26
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ csharp_style_expression_bodied_constructors = when_on_single_line
#prefer expression-bodied members for properties
csharp_style_expression_bodied_properties = when_on_single_line

#IDE0290: Use Primary Constructors
csharp_style_prefer_primary_constructors = false

#Style - expression level options

#prefer out variables to be declared before the method call
Expand Down
1 change: 1 addition & 0 deletions .github/actions/install-tools/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ runs:
dotnet-version: |
6.x
7.x
8.x
- name: Install .NET tools
shell: pwsh
Expand Down
2 changes: 1 addition & 1 deletion eng/DotNetAnalyzers.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AnalysisLevel>7.0</AnalysisLevel>
<AnalysisLevel>8.0</AnalysisLevel>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion eng/DotNetDefaults.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<!-- Sets the C# language version:
https://docs.microsoft.com/dotnet/csharp/language-reference/configure-language-version#c-language-version-reference
-->
<LangVersion>11.0</LangVersion>
<LangVersion>12.0</LangVersion>

<!-- Enable implicit usings:
https://docs.microsoft.com/dotnet/core/project-sdk/overview#implicit-using-directives
Expand Down
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.100",
"version": "8.0.100",
"allowPrerelease": false,
"rollForward": "latestFeature"
},
Expand Down
4 changes: 4 additions & 0 deletions src/Treasure.Utils.Argument/Argument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public static string NotNullOrEmpty([NotNull] string? value, [CallerArgumentExpr
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string NotNullOrWhiteSpace([NotNull] string? value, [CallerArgumentExpression(nameof(value))] string name = "")
{
#if NET8_0_OR_GREATER
ArgumentException.ThrowIfNullOrWhiteSpace(value, name);
#else
if (value is null)
{
throw new ArgumentNullException(name);
Expand All @@ -84,6 +87,7 @@ public static string NotNullOrWhiteSpace([NotNull] string? value, [CallerArgumen
{
throw new ArgumentException("The value cannot be null, empty, or white-space.", name);
}
#endif

return value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Treasure.Utils.Argument/Treasure.Utils.Argument.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net6.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0;netstandard2.1</TargetFrameworks>
<RootNamespace>Treasure.Utils</RootNamespace>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down
4 changes: 2 additions & 2 deletions test/Treasure.Utils.Argument.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// .\Run.ps1
// .\Run.ps1
// or
// dotnet run -c Release -f [net6.0 net7.0] --filter "*"
// dotnet run -c Release -f [net6.0 net7.0 net8.0] --filter "*"

#pragma warning disable CA1050
#pragma warning disable CA1812
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(TargetFrameworks);net7.0$(PlatformTFMSuffix);net6.0$(PlatformTFMSuffix)</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(TargetFrameworks);net8.0$(PlatformTFMSuffix);net7.0$(PlatformTFMSuffix);net6.0$(PlatformTFMSuffix)</TargetFrameworks>
<RootNamespace>Treasure.Utils.Benchmarks</RootNamespace>
<IsTestProject>false</IsTestProject>

Expand Down
2 changes: 1 addition & 1 deletion test/Treasure.Utils.Argument.Tests/ArgumentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static void Method(string? useMe)
public void NotNull()
{
// Arrange
int[] objectValue = Array.Empty<int>();
int[] objectValue = [];

// Act and assert
Argument.NotNull(objectValue);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net8.0;net7.0;net6.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(TargetFrameworks);$(DefaultNetStandardTestTFM)</TargetFrameworks>
<RootNamespace>Treasure.Utils.Tests</RootNamespace>
</PropertyGroup>
Expand Down

0 comments on commit f489b26

Please sign in to comment.