Skip to content

Commit

Permalink
Upgrade to .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad committed Dec 1, 2023
1 parent 5ddc080 commit 21d3614
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 93 deletions.
2 changes: 1 addition & 1 deletion TeachingRecordSystem/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"dotnet-format": {
"version": "7.4.441804",
"version": "8.0.453106",
"commands": [
"dotnet-format"
]
Expand Down
40 changes: 20 additions & 20 deletions TeachingRecordSystem/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageVersion Include="dbup-sqlserver" Version="5.0.37" />
<PackageVersion Include="DistributedLock.Azure" Version="1.0.0" />
<PackageVersion Include="DistributedLock.FileSystem" Version="1.0.1" />
<PackageVersion Include="EFCore.NamingConventions" Version="7.0.2" />
<PackageVersion Include="EFCore.NamingConventions" Version="8.0.0-rc.2" />
<PackageVersion Include="Faker.Net" Version="2.0.154" />
<PackageVersion Include="FakeXrmEasy.v9" Version="3.3.3" />
<PackageVersion Include="FluentValidation.AspNetCore" Version="11.3.0" />
Expand All @@ -29,24 +29,24 @@
<PackageVersion Include="MediatR" Version="12.1.1" />
<PackageVersion Include="Microsoft.ApplicationInsights" Version="2.21.0" />
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.13" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="7.0.13" />
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="7.0.13" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.13" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.13" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.7.1" />
<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="7.0.13" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyModel" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.DataAnnotations" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0" />
<PackageVersion Include="Microsoft.Identity.Web" Version="2.16.0" />
<PackageVersion Include="Microsoft.Identity.Web.GraphServiceClientBeta" Version="2.16.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
Expand All @@ -55,8 +55,8 @@
<PackageVersion Include="Microsoft.PowerPlatform.Dataverse.Client.Dynamics" Version="1.1.16" />
<PackageVersion Include="Microsoft.Web.LibraryManager.Build" Version="2.1.175" />
<PackageVersion Include="Moq" Version="4.20.70" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
<PackageVersion Include="NSwag.AspNetCore" Version="13.20.0" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageVersion Include="NSwag.AspNetCore" Version="14.0.0-preview010" />
<PackageVersion Include="NSwag.Examples" Version="1.0.11" />
<PackageVersion Include="Optional" Version="4.0.0" />
<PackageVersion Include="PdfSharpCore" Version="1.3.62" />
Expand All @@ -72,11 +72,11 @@
<PackageVersion Include="SerilogTimings" Version="3.0.1" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
<PackageVersion Include="System.Net.Http.Json" Version="7.0.1" />
<PackageVersion Include="System.Net.Http.Json" Version="8.0.0" />
<PackageVersion Include="System.Reactive" Version="6.0.0" />
<PackageVersion Include="xunit" Version="2.6.2" />
<PackageVersion Include="xunit.assert" Version="2.6.2" />
<PackageVersion Include="Xunit.DependencyInjection" Version="8.9.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.4" />
</ItemGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions TeachingRecordSystem/nuget.config
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="dotnet7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json" />
<add key="dotnet8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
<packageSource key="dotnet7">
<packageSource key="dotnet8">
<package pattern="dotnet-format" />
</packageSource>
</packageSourceMapping>
Expand Down
7 changes: 4 additions & 3 deletions TeachingRecordSystem/src/TeachingRecordSystem.Api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/aspnet:7.0
FROM mcr.microsoft.com/dotnet/aspnet:8.0
ARG GIT_SHA
ENV GitSha ${GIT_SHA}
COPY src/TeachingRecordSystem.Api/bin/Release/net7.0/publish/ App/
COPY src/TeachingRecordSystem.Cli/bin/Release/net7.0/publish/ TrsCli/
ENV ASPNETCORE_HTTP_PORTS 80
COPY src/TeachingRecordSystem.Api/bin/Release/net8.0/publish/ App/
COPY src/TeachingRecordSystem.Cli/bin/Release/net8.0/publish/ TrsCli/
WORKDIR /App

# install required fonts for PdfSharpCore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public GeneratedCrmTypeNameGenerator(ITypeNameGenerator innerGenerator)
_innerGenerator = innerGenerator;
}

public string Generate(JsonSchema schema, string typeNameHint, IEnumerable<string> reservedTypeNames)
public string Generate(JsonSchema schema, string? typeNameHint, IEnumerable<string> reservedTypeNames)
{
var name = _innerGenerator.Generate(schema, typeNameHint, reservedTypeNames);

// Generated CRM models for custom entities have a weird type name; fix that up here
// e.g. for the 'dfeta_inductionState' type use 'InductionState' in the API spec
if (name.StartsWith("dfeta_", StringComparison.OrdinalIgnoreCase))
{
var prefixTrimmedTypeName = name.Substring("dfeta_".Length);
var prefixTrimmedTypeName = name["dfeta_".Length..];
return prefixTrimmedTypeName[0..1].ToUpper() + prefixTrimmedTypeName[1..];
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next) =
});
}

app.UseSwaggerUi3(settings =>
app.UseSwaggerUi(settings =>
{
foreach (var version in Api.Constants.Versions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ public static IServiceCollection AddOpenApi(this IServiceCollection services, IC
settings.Version = OpenApiDocumentHelper.GetVersionName(version);
settings.Title = "Teaching Record System API";
settings.ApiGroupNames = new[] { OpenApiDocumentHelper.GetVersionName(version) };
settings.AddExamples(provider);
settings.TypeNameGenerator = new GeneratedCrmTypeNameGenerator(settings.TypeNameGenerator);
//settings.AddExamples(provider); // Broken with the current NSwag.Examples library
settings.SchemaSettings.TypeNameGenerator = new GeneratedCrmTypeNameGenerator(settings.SchemaSettings.TypeNameGenerator);

settings.DocumentProcessors.Add(new PopulateResponseDescriptionOperationProcessor());

settings.SchemaProcessors.Add(new RemoveCompositeValuesFromFlagsEnumSchemaProcessor());
settings.SchemaProcessors.Add(new RemoveExcludedEnumOptionsSchemaProcessor());
settings.SchemaSettings.SchemaProcessors.Add(new RemoveCompositeValuesFromFlagsEnumSchemaProcessor());
settings.SchemaSettings.SchemaProcessors.Add(new RemoveExcludedEnumOptionsSchemaProcessor());

settings.OperationProcessors.Add(new ResponseContentTypeOperationProcessor());
settings.OperationProcessors.Add(new PopulateResponseDescriptionOperationProcessor());
settings.OperationProcessors.Add(new AssignBinaryContentTypeFromProducesOperationProcessor());

settings.SchemaGenerator = new HandleOptionJsonSchemaGenerator(settings);
settings.SchemaSettings.ReflectionService = new UnwrapOptionTypesReflectionService();

settings.AddSecurity(SecuritySchemes.ApiKey, new NSwag.OpenApiSecurityScheme()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Namotion.Reflection;
using NJsonSchema.Generation;
using Optional;

namespace TeachingRecordSystem.Api.Infrastructure.OpenApi;

public class UnwrapOptionTypesReflectionService : SystemTextJsonReflectionService
{
protected override JsonTypeDescription GetDescription(
ContextualType contextualType,
SystemTextJsonSchemaGeneratorSettings settings,
Type originalType,
bool isNullable,
ReferenceTypeNullHandling defaultReferenceTypeNullHandling)
{
if (contextualType.Type.IsGenericType && contextualType.Type.GetGenericTypeDefinition() == typeof(Option<>))
{
originalType = contextualType.Type.GetGenericArguments()[0];
contextualType = originalType.ToContextualType();
}

return base.GetDescription(contextualType, settings, originalType, isNullable, defaultReferenceTypeNullHandling);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ public ApiKeyAuthenticationHandler(
IApiClientRepository clientRepository,
IOptionsMonitor<ApiKeyAuthenticationOptions> options,
ILoggerFactory logger,
UrlEncoder encoder,
ISystemClock clock)
: base(options, logger, encoder, clock)
UrlEncoder encoder)
: base(options, logger, encoder)
{
_clientRepository = clientRepository;
}
Expand Down
6 changes: 3 additions & 3 deletions TeachingRecordSystem/src/TeachingRecordSystem.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ public static void Main(string[] args)

app.Use((ctx, next) =>
{
ctx.Response.Headers.Add("X-Frame-Options", "deny");
ctx.Response.Headers.Add("X-Content-Type-Options", "nosniff");
ctx.Response.Headers.Add("X-XSS-Protection", "0");
ctx.Response.Headers.Append("X-Frame-Options", "deny");
ctx.Response.Headers.Append("X-Content-Type-Options", "nosniff");
ctx.Response.Headers.Append("X-XSS-Protection", "0");

return next();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<UserSecretsId>TeachingRecordSystemApi</UserSecretsId>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions TeachingRecordSystem/src/TeachingRecordSystem.Cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/sdk:7.0
COPY src/TeachingRecordSystem.Cli/bin/Release/net7.0/publish/ TrsCli/
FROM mcr.microsoft.com/dotnet/sdk:8.0
COPY src/TeachingRecordSystem.Cli/bin/Release/net8.0/publish/ TrsCli/
WORKDIR /TrsCli
ENV PATH="${PATH}:/TrsCli"
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TargetFramework>net8.0</TargetFramework>
<AssemblyName>trscli</AssemblyName>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFramework>net8.0</TargetFramework>
<UserSecretsId>TeachingRecordSystemCore</UserSecretsId>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine3.18
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine3.18
ARG GIT_SHA
ENV GitSha ${GIT_SHA}
COPY src/TeachingRecordSystem.SupportUi/bin/Release/net7.0/publish/ App/
ENV ASPNETCORE_HTTP_PORTS 80
COPY src/TeachingRecordSystem.SupportUi/bin/Release/net8.0/publish/ App/
WORKDIR /App

# Install Culture prerequisities
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<UserSecretsId>TeachingRecordSystemSupportUi</UserSecretsId>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ public TestAuthenticationHandler(
CurrentApiClientProvider currentApiClientProvider,
IOptionsMonitor<TestAuthenticationOptions> options,
ILoggerFactory logger,
UrlEncoder encoder,
ISystemClock clock) :
base(options, logger, encoder, clock)
UrlEncoder encoder) :
base(options, logger, encoder)
{
_currentApiClientProvider = currentApiClientProvider;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
<NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsTestProject>false</IsTestProject>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ install-tools:

# Run the trscli
cli *ARGS:
@cd {{solution-root / "src" / "TeachingRecordSystem.Cli"}} && dotnet {{"bin" / "Debug" / "net7.0" / "trscli.dll"}} {{ARGS}}
@cd {{solution-root / "src" / "TeachingRecordSystem.Cli"}} && dotnet {{"bin" / "Debug" / "net8.0" / "trscli.dll"}} {{ARGS}}

# Build the .NET solution
build:
Expand Down Expand Up @@ -112,7 +112,7 @@ set-ui-e2e-tests-secret key value:
@cd {{solution-root / "tests" / "TeachingRecordSystem.SupportUi.EndToEndTests"}} && dotnet user-secrets set "{{key}}" "{{value}}"

create-admin email name:
@cd {{solution-root / "src" / "TeachingRecordSystem.Cli"}} && dotnet {{"bin" / "Debug" / "net7.0" / "trscli.dll"}} create-admin --email {{email}} --name {{quote(name)}}
@cd {{solution-root / "src" / "TeachingRecordSystem.Cli"}} && dotnet {{"bin" / "Debug" / "net8.0" / "trscli.dll"}} create-admin --email {{email}} --name {{quote(name)}}

make *ARGS:
@make {{ARGS}}
Expand Down

0 comments on commit 21d3614

Please sign in to comment.