Skip to content

Commit

Permalink
Upgrade to .NET 9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
IEvangelist committed Nov 14, 2024
1 parent c0b8bd6 commit c7b1f70
Show file tree
Hide file tree
Showing 34 changed files with 146 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- '**.sln'

env:
DOTNET_VERSION: '8.0.x' # SDK version
DOTNET_VERSION: '9.0.x' # SDK version

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@main
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x

- name: Install dependencies
run: dotnet restore
Expand Down
14 changes: 7 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
<PackageVersion Include="GitHub.Actions.Core" Version="8.1.1" />
<PackageVersion Include="MarkdownBuilder" Version="0.2.0" />
<PackageVersion Include="Microsoft.Deployment.DotNet.Releases" Version="1.0.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageVersion Include="Octokit" Version="13.0.1" />
<PackageVersion Include="Pathological.ProjectSystem" Version="8.0.4" />
<PackageVersion Include="Pathological.ProjectSystem" Version="9.0.0" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/DotNet.Extensions/DotNet.Extensions.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions src/DotNet.Extensions/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
global using System.Text.Encodings.Web;
global using System.Text.Json;
global using System.Text.Json.Serialization;
global using System.Text.Json.Serialization.Metadata;
global using System.Threading.Tasks;
global using static System.Text.Json.JsonSerializer;
17 changes: 4 additions & 13 deletions src/DotNet.Extensions/ObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,11 @@ namespace DotNet.Extensions;

public static class ObjectExtensions
{
static readonly Lazy<JsonSerializerOptions> s_lazyOptions = new(() => new()
{
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) },
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString,
PropertyNameCaseInsensitive = true,
AllowTrailingCommas = true,
});
public static string? ToJson<T>(this T value, JsonTypeInfo<T> jsonTypeInfo) =>
value is null ? null : Serialize(value, jsonTypeInfo);

public static string? ToJson(this object value, JsonSerializerOptions? options = default) =>
value is null ? null : Serialize(value, options ?? s_lazyOptions.Value);

public static T? FromJson<T>(this string? json, JsonSerializerOptions? options = default) =>
string.IsNullOrWhiteSpace(json) ? default : Deserialize<T>(json, options ?? s_lazyOptions.Value);
public static T? FromJson<T>(this string? json, JsonTypeInfo<T> jsonTypeInfo) =>
string.IsNullOrWhiteSpace(json) ? default : Deserialize<T>(json, jsonTypeInfo);

public static DateTime? ToDateTime(this string? value) =>
value is null ? default : DateTime.TryParse(value, out global::System.DateTime dateTime) ? dateTime : null;
Expand Down
4 changes: 2 additions & 2 deletions src/DotNet.GitHub/DotNet.GitHub.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
8 changes: 2 additions & 6 deletions src/DotNet.GitHub/GitHubGraphQLClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ ... on Issue {
""";

static readonly Uri s_graphQLUri = new("https://api.github.com/graphql");
static readonly JsonSerializerOptions s_options = new()
{
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) },
PropertyNameCaseInsensitive = true
};

readonly HttpClient _httpClient;
readonly ILogger<GitHubGraphQLClient> _logger;
Expand Down Expand Up @@ -63,7 +58,8 @@ public GitHubGraphQLClient(HttpClient httpClient, ILogger<GitHubGraphQLClient> l
response.EnsureSuccessStatusCode();

string json = await response.Content.ReadAsStringAsync();
GraphQLResult<ExistingIssue>? result = json.FromJson<GraphQLResult<ExistingIssue>>(s_options);
GraphQLResult<ExistingIssue>? result = json.FromJson<GraphQLResult<ExistingIssue>>(
GitHubJsonSerializerContext.Default.GraphQLResultExistingIssue);

return (false, result?.Data?.Search?.Nodes
?.Where(i => i.State == ItemState.Open)
Expand Down
15 changes: 15 additions & 0 deletions src/DotNet.GitHub/GitHubJsonSerializerContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace DotNet.GitHub;

[JsonSourceGenerationOptions(

Check warning on line 6 in src/DotNet.GitHub/GitHubJsonSerializerContext.cs

View workflow job for this annotation

GitHub Actions / build

The member 'DotNet.GitHub.GitHubJsonSerializerContext' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1034)

Check warning on line 6 in src/DotNet.GitHub/GitHubJsonSerializerContext.cs

View workflow job for this annotation

GitHub Actions / build

The member 'DotNet.GitHub.GitHubJsonSerializerContext' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1034)

Check warning on line 6 in src/DotNet.GitHub/GitHubJsonSerializerContext.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The member 'DotNet.GitHub.GitHubJsonSerializerContext' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1034)

Check warning on line 6 in src/DotNet.GitHub/GitHubJsonSerializerContext.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The member 'DotNet.GitHub.GitHubJsonSerializerContext' has been annotated with 'JsonStringEnumConverter' which is not supported in native AOT. Consider using the generic 'JsonStringEnumConverter<TEnum>' instead. (https://learn.microsoft.com/dotnet/fundamentals/syslib-diagnostics/syslib1034)
PropertyNameCaseInsensitive = true,
Converters = [ typeof(JsonStringEnumConverter) ]
)]
[JsonSerializable(typeof(GraphQLRequest))]
[JsonSerializable(typeof(ExistingIssue))]
[JsonSerializable(typeof(GraphQLResult<ExistingIssue>))]
internal partial class GitHubJsonSerializerContext : JsonSerializerContext
{
}
5 changes: 3 additions & 2 deletions src/DotNet.GitHub/GraphQLRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public record GraphQLRequest
public string Query { get; init; } = "";

[JsonPropertyName("variables")]
public Dictionary<string, string> Variables { get; init; } = new();
public Dictionary<string, string> Variables { get; init; } = [];

public override string ToString() => this.ToJson()!;
public override string ToString() =>
this.ToJson(GitHubJsonSerializerContext.Default.GraphQLRequest)!;
}
10 changes: 4 additions & 6 deletions src/DotNet.GitHub/ModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ The following project file(s) target a .NET version that's no longer supported.
new("End of life"),
new("Release notes"),
new("Nearest LTS TFM version")),
new[]
{
[
new MarkdownTableRow(
$"`{tfmSupport.TargetFrameworkMoniker}`",
tfmSupport.Release.EndOfLifeDate.HasValue
Expand All @@ -39,7 +38,7 @@ The following project file(s) target a .NET version that's no longer supported.
$"{tfmSupport.TargetFrameworkMoniker} release notes", tfmSupport.Release.ReleaseNotesUrl)
.ToString(),
$"`{tfmSupport.NearestLtsVersion}`")
});
]);

document.AppendList(
new MarkdownList(
Expand Down Expand Up @@ -96,8 +95,7 @@ The following Dockerfile(s) target a .NET version that's no longer supported.
new("End of life"),
new("Release notes"),
new("Nearest LTS TFM version")),
new[]
{
[
new MarkdownTableRow(
$"`{tfmSupport.TargetFrameworkMoniker}`",
tfmSupport.Release.EndOfLifeDate.HasValue
Expand All @@ -106,7 +104,7 @@ The following Dockerfile(s) target a .NET version that's no longer supported.
$"{tfmSupport.TargetFrameworkMoniker} release notes", tfmSupport.Release.ReleaseNotesUrl)
.ToString(),
$"`{tfmSupport.NearestLtsVersion}`")
});
]);

document.AppendList(
new MarkdownList(
Expand Down
4 changes: 2 additions & 2 deletions src/DotNet.Models/DotNet.Models.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/DotNet.Releases/DotNet.Releases.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/DotNet.Releases/Framework/FrameworkReleaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ await cache.GetOrCreateAsync(
string json = await reader.ReadToEndAsync();
return json.FromJson<FrameworkRelease>(new());
return json.FromJson<FrameworkRelease>(
ReleasesJsonSerializerContext.Default.FrameworkRelease);
});

yield return frameworkRelease!;
Expand Down
1 change: 1 addition & 0 deletions src/DotNet.Releases/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

global using System.Collections.Concurrent;
global using System.Collections.ObjectModel;
global using System.Text.Json.Serialization;
global using System.Reflection;
global using DotNet.Extensions;
global using DotNet.Models;
Expand Down
7 changes: 7 additions & 0 deletions src/DotNet.Releases/ReleasesJsonSerializerContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace DotNet.Releases;

[JsonSerializable(typeof(FrameworkRelease))]
internal partial class ReleasesJsonSerializerContext : JsonSerializerContext;
2 changes: 1 addition & 1 deletion src/DotNet.VersionSweeper/DotNet.VersionSweeper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateRuntimeConfigurationFile>true</GenerateRuntimeConfigurationFile>
<Nullable>enable</Nullable>
Expand Down
1 change: 1 addition & 0 deletions src/DotNet.VersionSweeper/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

global using System.Text;
global using System.Text.Json;
global using System.Text.Json.Serialization;
global using Actions.Core.Extensions;
global using Actions.Core.Services;
Expand Down
6 changes: 3 additions & 3 deletions src/DotNet.VersionSweeper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ await CreateAndEnqueueAsync(
options, o => projectSupportReports.ToMarkdownBody(tfm, o));
}
}
else // We we're instructed to create pull requests.
else // We were instructed to create pull requests.
{
string[] upgradeProjects =
tfmToProjectSupportReports.Values
Expand All @@ -166,7 +166,7 @@ await CreateAndEnqueueAsync(
hasRemainingWork = upgradeProjects is { Length: > 0 };
if (hasRemainingWork)
{
string json = upgradeProjects.ToJson() ?? "";
string json = upgradeProjects.ToJson(SweeperJsonSerializerContext.Default.StringArray) ?? "";
await job.SetOutputAsync("upgrade-projects", json);
}
}
Expand Down Expand Up @@ -194,7 +194,7 @@ await CreateAndEnqueueAsync(
}

await job.SetOutputAsync(
"has-remaining-work", hasRemainingWork.ToJson() ?? "false");
"has-remaining-work", hasRemainingWork);
}
catch (Exception ex)
{
Expand Down
14 changes: 14 additions & 0 deletions src/DotNet.VersionSweeper/SweeperJsonSerializerContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

[JsonSourceGenerationOptions(
defaults: JsonSerializerDefaults.Web,
WriteIndented = true,
UseStringEnumConverter = true,
AllowTrailingCommas = true,
NumberHandling = JsonNumberHandling.AllowReadingFromString,
PropertyNameCaseInsensitive = false,
IncludeFields = true)]
[JsonSerializable(typeof(string[]))]
[JsonSerializable(typeof(VersionSweeperConfig))]
internal partial class SweeperJsonSerializerContext : JsonSerializerContext;
2 changes: 1 addition & 1 deletion src/DotNet.VersionSweeper/VersionSweeperConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal static async Task<VersionSweeperConfig> ReadAsync(string root, ICoreSer
job.WriteInfo($"Reading '{fullPath}' config file.");

string configJson = await File.ReadAllTextAsync(fullPath);
VersionSweeperConfig config = configJson.FromJson<VersionSweeperConfig>() ?? new();
VersionSweeperConfig config = configJson.FromJson<VersionSweeperConfig>(SweeperJsonSerializerContext.Default.VersionSweeperConfig) ?? new();

job.WriteInfo($"Read {config.Ignore.Length} pattern(s) to ignore:");
job.WriteInfo($"{string.Join(",", config.Ignore.Select(val => $"\t{val}"))}");
Expand Down
8 changes: 4 additions & 4 deletions test/DotNet.ExtensionsTests/DotNet.ExtensionsTests.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.6.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Loading

0 comments on commit c7b1f70

Please sign in to comment.