Skip to content

Commit b620abc

Browse files
authored
Merge pull request #35 from jamesmontemagno/dotnet9-2
updates and fixes for .net 9
2 parents b6df3df + 28e7ccc commit b620abc

File tree

12 files changed

+114
-71
lines changed

12 files changed

+114
-71
lines changed

.devcontainer/devcontainer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": ".NET in Codespaces",
3-
"image": "mcr.microsoft.com/dotnet/sdk:8.0",
3+
"image": "mcr.microsoft.com/dotnet/sdk:9.0",
44
"features": {
55
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
66
"ghcr.io/devcontainers/features/github-cli:1": {
@@ -15,8 +15,8 @@
1515
"ghcr.io/devcontainers/features/common-utils:2": {},
1616
"ghcr.io/devcontainers/features/dotnet:2": {
1717
"version": "none",
18-
"dotnetRuntimeVersions": "7.0",
19-
"aspNetCoreRuntimeVersions": "7.0"
18+
"dotnetRuntimeVersions": "8.0",
19+
"aspNetCoreRuntimeVersions": "8.0"
2020
}
2121
},
2222
"customizations": {
@@ -42,7 +42,7 @@
4242
},
4343
"remoteEnv": {
4444
"DOTNET_MULTILEVEL_LOOKUP": "0",
45-
"TARGET": "net8.0"
45+
"TARGET": "net9.0"
4646
},
4747
"portsAttributes": {
4848
"8080": {

.github/workflows/build.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build Backend and Frontend
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
name: Build All Projects
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
project:
17+
- SampleApp/BackEnd/BackEnd.csproj
18+
- SampleApp/FrontEnd/FrontEnd.csproj
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Setup .NET
25+
uses: actions/setup-dotnet@v4
26+
with:
27+
dotnet-version: '9.0.x'
28+
29+
- name: Restore dependencies
30+
run: dotnet restore ${{ matrix.project }}
31+
32+
- name: Build project
33+
run: dotnet build ${{ matrix.project }} --no-restore --configuration Release

.vscode/launch.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88
"order": 1
99
},
1010
"configurations": [
11-
"Back End",
12-
"Front End"
11+
"BackEnd",
12+
"FrontEnd"
1313
]
1414
}
1515
],
1616
"configurations": [
1717
{
18-
"name": "Back End",
18+
"name": "BackEnd",
1919
"type": "coreclr",
2020
"request": "launch",
2121
"preLaunchTask": "build backend",
22-
"program": "${workspaceFolder}/SampleApp/BackEnd/bin/Debug/net8.0/BackEnd.dll",
22+
"program": "${workspaceFolder}/SampleApp/BackEnd/bin/Debug/net9.0/BackEnd.dll",
2323
"args": [],
2424
"cwd": "${workspaceFolder}/SampleApp/BackEnd",
2525
"stopAtEntry": false,
2626
"serverReadyAction": {
2727
"action": "openExternally",
2828
"pattern": "\\bNow listening on:\\s+(https?://\\S+)",
29-
"uriFormat": "%s/swagger"
29+
"uriFormat": "%s/scalar"
3030
},
3131
"env": {
3232
"ASPNETCORE_ENVIRONMENT": "Development"
@@ -36,11 +36,11 @@
3636
}
3737
},
3838
{
39-
"name": "Front End",
39+
"name": "FrontEnd",
4040
"type": "coreclr",
4141
"request": "launch",
4242
"preLaunchTask": "build frontend",
43-
"program": "${workspaceFolder}/SampleApp/FrontEnd/bin/Debug/net8.0/FrontEnd.dll",
43+
"program": "${workspaceFolder}/SampleApp/FrontEnd/bin/Debug/net9.0/FrontEnd.dll",
4444
"args": [],
4545
"cwd": "${workspaceFolder}/SampleApp/FrontEnd",
4646
"stopAtEntry": false,

SampleApp/BackEnd/BackEnd.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<InvariantGlobalization>true</InvariantGlobalization>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0-preview.4.23260.4" />
12-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
11+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.*" />
12+
<PackageReference Include="Scalar.AspNetCore" Version="2.0.*" />
1313
</ItemGroup>
1414

1515
</Project>

SampleApp/BackEnd/Program.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
1+
using Microsoft.AspNetCore.OpenApi;
2+
using Scalar.AspNetCore;
3+
14
var builder = WebApplication.CreateBuilder(args);
25

36
// Add services to the container.
4-
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
5-
builder.Services.AddEndpointsApiExplorer();
6-
builder.Services.AddSwaggerGen();
7+
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
8+
builder.Services.AddOpenApi(options =>
9+
{
10+
// current workaround for port forwarding in codespaces
11+
// https://github.com/dotnet/aspnetcore/issues/57332
12+
options.AddDocumentTransformer((document, context, ct) =>
13+
{
14+
document.Servers = [];
15+
return Task.CompletedTask;
16+
});
17+
});
718

819
var app = builder.Build();
920

1021
// Configure the HTTP request pipeline.
1122
if (app.Environment.IsDevelopment())
1223
{
13-
app.UseSwagger();
14-
app.UseSwaggerUI();
24+
app.MapOpenApi();
25+
app.MapScalarApiReference();
1526
}
1627

28+
app.UseHttpsRedirection();
29+
1730
var summaries = new[]
1831
{
1932
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
@@ -31,8 +44,7 @@
3144
.ToArray();
3245
return forecast;
3346
})
34-
.WithName("GetWeatherForecast")
35-
.WithOpenApi();
47+
.WithName("GetWeatherForecast");
3648

3749
app.Run();
3850

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
namespace FrontEnd.Data
1+
namespace FrontEnd.Data;
2+
3+
public class WeatherForecast
24
{
3-
public class WeatherForecast
4-
{
5-
public DateOnly Date { get; set; }
5+
public DateOnly Date { get; set; }
66

7-
public int TemperatureC { get; set; }
7+
public int TemperatureC { get; set; }
88

9-
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
9+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
1010

11-
public string? Summary { get; set; }
12-
}
13-
}
11+
public string? Summary { get; set; }
12+
}
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
namespace FrontEnd.Data
2-
{
3-
public class WeatherForecastClient
4-
{
5-
private HttpClient _httpClient;
6-
private ILogger<WeatherForecastClient> _logger;
1+
namespace FrontEnd.Data;
72

8-
public WeatherForecastClient(HttpClient httpClient, ILogger<WeatherForecastClient> logger)
9-
{
10-
_httpClient = httpClient;
11-
_logger = logger;
12-
}
3+
public class WeatherForecastClient
4+
{
5+
private HttpClient _httpClient;
6+
private ILogger<WeatherForecastClient> _logger;
137

14-
public async Task<WeatherForecast[]> GetForecastAsync(DateTime? startDate)
15-
=> await _httpClient.GetFromJsonAsync<WeatherForecast[]>($"WeatherForecast?startDate={startDate}");
8+
public WeatherForecastClient(HttpClient httpClient, ILogger<WeatherForecastClient> logger)
9+
{
10+
_httpClient = httpClient;
11+
_logger = logger;
1612
}
17-
}
13+
14+
public async Task<WeatherForecast[]> GetForecastAsync(DateTime? startDate)
15+
=> await _httpClient.GetFromJsonAsync<WeatherForecast[]>($"WeatherForecast?startDate={startDate}") ?? [];
16+
}

SampleApp/FrontEnd/FrontEnd.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>

SampleApp/FrontEnd/Pages/Error.cshtml.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@
22
using Microsoft.AspNetCore.Mvc.RazorPages;
33
using System.Diagnostics;
44

5-
namespace FrontEnd.Pages
5+
namespace FrontEnd.Pages;
6+
7+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8+
[IgnoreAntiforgeryToken]
9+
public class ErrorModel : PageModel
610
{
7-
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8-
[IgnoreAntiforgeryToken]
9-
public class ErrorModel : PageModel
10-
{
11-
public string? RequestId { get; set; }
11+
public string? RequestId { get; set; }
1212

13-
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
13+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
1414

15-
private readonly ILogger<ErrorModel> _logger;
15+
private readonly ILogger<ErrorModel> _logger;
1616

17-
public ErrorModel(ILogger<ErrorModel> logger)
18-
{
19-
_logger = logger;
20-
}
17+
public ErrorModel(ILogger<ErrorModel> logger)
18+
{
19+
_logger = logger;
20+
}
2121

22-
public void OnGet()
23-
{
24-
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
25-
}
22+
public void OnGet()
23+
{
24+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
2625
}
27-
}
26+
}

images/Swagger.png

-109 KB
Binary file not shown.

0 commit comments

Comments
 (0)