Skip to content

Commit

Permalink
Update to ASP.NET Core 8 (#1664)
Browse files Browse the repository at this point in the history
- Update to RC1 of ASP.NET Core 8.
- Use the new `UseArtifactsOutput` property for the output paths and adjust the build scripts accordingly.
- Use the new `TypeInfoResolverChain` property to add the custom JSON serializer context.
- Replace NodaTime with `TimeProvider`.
- Remove Microsoft.SourceLink.GitHub as it is now added automatically by the .NET SDK.
- Enable the source generator for Minimal APIs.
- Remove Facebook API version override.
  • Loading branch information
martincostello authored Sep 25, 2023
1 parent 28de660 commit 8b842ae
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 61 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ env:
DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1
FORCE_COLOR: 1
NUGET_XMLDOC_MODE: skip
PUBLISH_RUNTIME: win10-x64
PUBLISH_RUNTIME: win-x64
TERM: xterm

permissions:
Expand Down Expand Up @@ -105,7 +105,7 @@ jobs:
if: runner.os == 'Windows' && success()
with:
name: webapp
path: ./artifacts/publish
path: ./artifacts/publish/LondonTravel.Site/release_${{ env.PUBLISH_RUNTIME }}
if-no-files-found: error

- name: Publish screenshots
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ jobs:
If ($StatusCode -ne 200) {
throw "Failed to successfully connect to website after $Attempts attempts."
}
New-Item -Path "${env:GITHUB_WORKSPACE}/artifacts" -ItemType Directory | Out-Null
New-Item -Path "${env:GITHUB_WORKSPACE}/artifacts/lighthouse" -ItemType Directory | Out-Null
- name: Lighthouse
uses: foo-software/lighthouse-check-action@f78f162ef0ecd48a18244c427959f0b79ef4d553 # v10.0.0
id: lighthouse
with:
device: 'all'
gitHubAccessToken: ${{ secrets.LIGHTHOUSE_ACCESS_TOKEN }}
outputDirectory: ${{ github.workspace }}/artifacts
outputDirectory: ${{ github.workspace }}/artifacts/lighthouse
prCommentEnabled: true
urls: 'https://localhost:5001'
wait: true
Expand All @@ -90,5 +90,5 @@ jobs:
if: ${{ always() }}
with:
name: lighthouse
path: ${{ github.workspace }}/artifacts
path: ${{ github.workspace }}/artifacts/lighthouse
if-no-files-found: ignore
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/LondonTravel.Site/bin/Debug/net7.0/LondonTravel.Site.dll",
"program": "${workspaceFolder}/src/LondonTravel.Site/bin/Debug/net8.0/LondonTravel.Site.dll",
"args": [],
"cwd": "${workspaceFolder}/src/LondonTravel.Site",
"stopAtEntry": false,
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
3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>$(PackageProjectUrl).git</RepositoryUrl>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<VersionPrefix>7.0.0</VersionPrefix>
<VersionPrefix>8.0.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<UseArtifactsOutput>true</UseArtifactsOutput>
</PropertyGroup>
<PropertyGroup Condition=" '$(CI)' != '' or !Exists('$(MSBuildThisFileDirectory)\src\LondonTravel.Site\node_modules') ">
<InstallWebPackages>true</InstallWebPackages>
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,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
19 changes: 7 additions & 12 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project>
<PropertyGroup>
<AspNetSecurityOAuthVersion>7.0.4</AspNetSecurityOAuthVersion>
<NodaTimeVersion>3.1.9</NodaTimeVersion>
<SwashbuckleAspNetCoreVersion>6.5.0</SwashbuckleAspNetCoreVersion>
</PropertyGroup>
<ItemGroup>
Expand All @@ -17,22 +16,19 @@
<PackageVersion Include="JustEat.HttpClientInterception" Version="4.0.0" />
<PackageVersion Include="MartinCostello.Logging.XUnit" Version="0.3.0" />
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Facebook" Version="7.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="7.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="7.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Twitter" Version="7.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.AzureAppServices.HostingStartup" Version="7.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.11" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Facebook" Version="8.0.0-rc.1.23421.29" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="8.0.0-rc.1.23421.29" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="8.0.0-rc.1.23421.29" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Twitter" Version="8.0.0-rc.1.23421.29" />
<PackageVersion Include="Microsoft.AspNetCore.AzureAppServices.HostingStartup" Version="8.0.0-rc.1.23421.29" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.0-rc.1.23421.29" />
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.35.4" />
<PackageVersion Include="Microsoft.DotNet.XliffTasks" Version="1.0.0-beta.21452.1" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="7.0.11" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="8.0.0-rc.1.23421.29" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageVersion Include="Microsoft.Playwright" Version="1.37.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="Microsoft.TypeScript.MSBuild" Version="5.2.2" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
<PackageVersion Include="NodaTime" Version="$(NodaTimeVersion)" />
<PackageVersion Include="NodaTime.Testing" Version="$(NodaTimeVersion)" />
<PackageVersion Include="Polly" Version="7.2.4" />
<PackageVersion Include="Refit" Version="7.0.0" />
<PackageVersion Include="ReportGenerator" Version="5.1.25" />
Expand All @@ -50,7 +46,6 @@
<PackageVersion Include="Xunit.SkippableFact" Version="1.4.13" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
Expand Down
13 changes: 2 additions & 11 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#! /usr/bin/env pwsh
param(
[Parameter(Mandatory = $false)][string] $Configuration = "Release",
[Parameter(Mandatory = $false)][string] $OutputPath = "",
[Parameter(Mandatory = $false)][switch] $SkipTests,
[Parameter(Mandatory = $false)][string] $Runtime = ""
)
Expand All @@ -14,10 +12,6 @@ $sdkFile = Join-Path $solutionPath "global.json"

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

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

$installDotNetSdk = $false;

if (($null -eq (Get-Command "dotnet" -ErrorAction SilentlyContinue)) -and ($null -eq (Get-Command "dotnet.exe" -ErrorAction SilentlyContinue))) {
Expand Down Expand Up @@ -82,7 +76,7 @@ function DotNetTest {
$additionalArgs += "GitHubActions;report-warnings=false"
}

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

if ($LASTEXITCODE -ne 0) {
throw "dotnet test failed with exit code $LASTEXITCODE"
Expand All @@ -92,8 +86,6 @@ function DotNetTest {
function DotNetPublish {
param([string]$Project)

$publishPath = (Join-Path $OutputPath "publish")

$additionalArgs = @()

if (![string]::IsNullOrEmpty($Runtime)) {
Expand All @@ -102,7 +94,7 @@ function DotNetPublish {
$additionalArgs += $Runtime
}

& $dotnet publish $Project --output $publishPath --configuration $Configuration $additionalArgs
& $dotnet publish $Project $additionalArgs

if ($LASTEXITCODE -ne 0) {
throw "dotnet publish failed with exit code $LASTEXITCODE"
Expand All @@ -128,4 +120,3 @@ if ($SkipTests -eq $false) {
DotNetTest $project
}
}

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.401",
"version": "8.0.100-rc.1.23463.5",
"allowPrerelease": false,
"rollForward": "latestMajor"
}
Expand Down
9 changes: 4 additions & 5 deletions src/LondonTravel.Site/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using NodaTime;

namespace MartinCostello.LondonTravel.Site.Controllers;

Expand All @@ -26,22 +25,22 @@ public partial class AccountController : Controller
private readonly UserManager<LondonTravelUser> _userManager;
private readonly SignInManager<LondonTravelUser> _signInManager;
private readonly ISiteTelemetry _telemetry;
private readonly IClock _clock;
private readonly TimeProvider _timeProvider;
private readonly bool _isEnabled;
private readonly ILogger _logger;

public AccountController(
UserManager<LondonTravelUser> userManager,
SignInManager<LondonTravelUser> signInManager,
ISiteTelemetry telemetry,
IClock clock,
TimeProvider timeProvider,
SiteOptions siteOptions,
ILogger<AccountController> logger)
{
_userManager = userManager;
_signInManager = signInManager;
_telemetry = telemetry;
_clock = clock;
_timeProvider = timeProvider;
_logger = logger;

_isEnabled =
Expand Down Expand Up @@ -289,7 +288,7 @@ private IActionResult RedirectToLocal(string? returnUrl)

var user = new LondonTravelUser()
{
CreatedAt = _clock.GetCurrentInstant().ToDateTimeUtc(),
CreatedAt = _timeProvider.GetUtcNow().UtcDateTime,
Email = email,
GivenName = givenName,
Surname = surname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ public static AuthenticationBuilder TryAddFacebook(

if (IsProviderEnabled(name, options))
{
builder.AddFacebook((p) =>
{
p.AuthorizationEndpoint = "https://www.facebook.com/v14.0/dialog/oauth";
p.TokenEndpoint = "https://graph.facebook.com/v14.0/oauth/access_token";
p.UserInformationEndpoint = "https://graph.facebook.com/v14.0/me";
})
builder.AddFacebook()
.Configure<FacebookOptions>(name);
}

Expand Down Expand Up @@ -261,9 +256,9 @@ private static void Configure<T>(

options.Events.OnTicketReceived = (context) =>
{
var clock = context.HttpContext.RequestServices.GetRequiredService<ISystemClock>();
var provider = context.HttpContext.RequestServices.GetRequiredService<TimeProvider>();

context.Properties!.ExpiresUtc = clock.UtcNow.AddDays(150);
context.Properties!.ExpiresUtc = provider.GetUtcNow().AddDays(150);
context.Properties.IsPersistent = true;

return Task.CompletedTask;
Expand Down
13 changes: 11 additions & 2 deletions src/LondonTravel.Site/LondonTravel.Site.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@
<PropertyGroup>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<Description>https://londontravel.martincostello.com/</Description>
<!--
HACK Disable configuration binding source generator due to issues in RC.1 that will be fixed in RC.2:
- https://github.com/dotnet/runtime/issues/90851
- https://github.com/dotnet/runtime/issues/90987
- https://github.com/dotnet/runtime/issues/91258
-->
<!--
<EnableConfigurationBindingGenerator>true</EnableConfigurationBindingGenerator>
-->
<EnableRequestDelegateGenerator>true</EnableRequestDelegateGenerator>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CA1716</NoWarn>
<OutputType>Exe</OutputType>
<PreserveCompilationContext>true</PreserveCompilationContext>
<RootNamespace>MartinCostello.LondonTravel.Site</RootNamespace>
<SatelliteResourceLanguages>en,en-GB,en-US,qps-Ploc</SatelliteResourceLanguages>
<Summary>Website for the London Travel Amazon Alexa skill.</Summary>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>latest</TypeScriptToolsVersion>
<UserSecretsId>londontravel.martincostello.com</UserSecretsId>
Expand Down Expand Up @@ -39,7 +49,6 @@
<PackageReference Include="Microsoft.DotNet.XliffTasks" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" />
<PackageReference Include="NodaTime" />
<PackageReference Include="Polly" />
<PackageReference Include="Refit" />
<PackageReference Include="Serilog" />
Expand Down
1 change: 0 additions & 1 deletion src/LondonTravel.Site/Pages/Technology/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
<li>jquery.lazyload</li>
<li>Microsoft Accounts</li>
<li>Moment.js</li>
<li>NodaTime</li>
<li>npm</li>
<li>NSubstitute</li>
<li>NuGet</li>
Expand Down
8 changes: 2 additions & 6 deletions src/LondonTravel.Site/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache 2.0 license. See the LICENSE file in the project root for full license information.

using System.IO.Compression;
using System.Text.Json.Serialization.Metadata;
using MartinCostello.LondonTravel.Site;
using MartinCostello.LondonTravel.Site.Extensions;
using MartinCostello.LondonTravel.Site.Options;
Expand All @@ -20,7 +19,6 @@
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using NodaTime;

var builder = WebApplication.CreateBuilder(args);

Expand Down Expand Up @@ -134,9 +132,7 @@
options.SerializerOptions.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull;
options.SerializerOptions.PropertyNameCaseInsensitive = false;
options.SerializerOptions.WriteIndented = true;
options.SerializerOptions.TypeInfoResolver = JsonTypeInfoResolver.Combine(
ApplicationJsonSerializerContext.Default,
new DefaultJsonTypeInfoResolver());
options.SerializerOptions.TypeInfoResolverChain.Add(ApplicationJsonSerializerContext.Default);
});

builder.Services.Configure<StaticFileOptions>((options) =>
Expand Down Expand Up @@ -172,7 +168,7 @@
};
});

builder.Services.AddSingleton<IClock>((_) => SystemClock.Instance);
builder.Services.AddSingleton(TimeProvider.System);
builder.Services.AddSingleton<ISiteTelemetry, SiteTelemetry>();
builder.Services.AddSingleton<ITelemetryInitializer, SiteTelemetryInitializer>();
builder.Services.AddSingleton<ITflServiceFactory, TflServiceFactory>();
Expand Down
2 changes: 1 addition & 1 deletion src/LondonTravel.Site/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/LondonTravel.Site/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "london-travel-site",
"private": true,
"version": "7.0.0",
"version": "8.0.0",
"description": "The companion site for the London Travel Amazon Alexa skill",
"scripts": {
"build": "npm run compile && npm run format && npm run lint",
Expand Down
2 changes: 1 addition & 1 deletion tests/LondonTravel.Site.Tests/BrowserFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace MartinCostello.LondonTravel.Site;
public class BrowserFixture
{
private const string VideosDirectory = "videos";
private const string AssetsDirectory = ".";
private static readonly string AssetsDirectory = Path.Combine("..", "..", "..");

public BrowserFixture(
BrowserFixtureOptions options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
},
{
"comment": "User information resource for Google login",
"uri": "https://www.googleapis.com/oauth2/v2/userinfo",
"uri": "https://www.googleapis.com/oauth2/v3/userinfo",
"contentFormat": "json",
"contentJson": {
"id": "c91599d6-ab86-452c-96d3-6e8eb45585f2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PreserveCompilationContext>true</PreserveCompilationContext>
<RootNamespace>MartinCostello.LondonTravel.Site</RootNamespace>
<Summary>Tests for the London Travel website</Summary>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Content Include="testsettings.json;xunit.runner.json;Integration\apple-test-cert.p8;Integration\*-http-bundle.json" CopyToOutputDirectory="PreserveNewest" />
Expand Down

0 comments on commit 8b842ae

Please sign in to comment.