Skip to content

Commit 8dc140e

Browse files
committed
[gh-1349] Update Server and Container Host to .NET 9
1 parent 6582e67 commit 8dc140e

24 files changed

+182
-175
lines changed

Diff for: .github/workflows/container-host-edge.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ on:
1414

1515
jobs:
1616
build:
17-
name: 'Build (.NET 8)'
17+
name: 'Build (.NET 9)'
1818
# https://github.community/t/duplicate-checks-on-push-and-pull-request-simultaneous-event/18012/5
1919
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
2020
runs-on: windows-latest
2121
env:
2222
NUGET_PACKAGES: ${{github.workspace}}/.nuget/packages
2323
steps:
24-
- uses: actions/checkout@v3
24+
- uses: actions/checkout@v4
2525
with:
2626
submodules: 'true'
27-
- uses: actions/setup-dotnet@v3
27+
- uses: actions/setup-dotnet@v4
2828
with:
29-
dotnet-version: 8.0.x
29+
dotnet-version: 9.0.x
3030
- uses: microsoft/setup-msbuild@v1.1
3131

3232
# https://github.com/actions/setup-dotnet/issues/155
@@ -47,7 +47,7 @@ jobs:
4747
- run: dotnet build source/Tests --configuration Release
4848
- run: dotnet test source/Tests --no-build --configuration Release
4949
- run: dotnet publish source/Container.Manager --no-build --configuration Release
50-
- run: Compress-Archive -Path 'source/Container.Manager/bin/Release/net8.0/publish/*' -DestinationPath 'Container.Manager.zip'
50+
- run: Compress-Archive -Path 'source/Container.Manager/bin/Release/net9.0/publish/*' -DestinationPath 'Container.Manager.zip'
5151
shell: pwsh
5252

5353
- uses: actions/upload-artifact@v3

Diff for: .github/workflows/server-edge.yml

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ on:
1616

1717
jobs:
1818
build-core:
19-
name: 'Build (.NET 8)'
19+
name: 'Build (.NET 9)'
2020
# https://github.community/t/duplicate-checks-on-push-and-pull-request-simultaneous-event/18012/5
2121
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
2222
runs-on: windows-latest
2323
env:
2424
NUGET_PACKAGES: ${{github.workspace}}/.nuget/packages
2525
steps:
26-
- uses: actions/checkout@v3
26+
- uses: actions/checkout@v4
2727
with:
2828
submodules: 'true'
29-
- uses: actions/setup-dotnet@v3
29+
- uses: actions/setup-dotnet@v4
3030
with:
31-
dotnet-version: 8.0.x
31+
dotnet-version: 9.0.x
3232
- uses: microsoft/setup-msbuild@v1.1
3333

3434
# https://github.com/actions/setup-dotnet/issues/155
@@ -52,9 +52,9 @@ jobs:
5252
- run: dotnet test source/Tests --no-build --configuration Release
5353
- run: dotnet publish source/Server --no-build --configuration Release
5454
- run: dotnet publish source/WebApp.Server --no-build --configuration Release /p:ErrorOnDuplicatePublishOutputFiles=false
55-
- run: Compress-Archive -Path 'source/Server/bin/Release/net8.0/publish/*' -DestinationPath 'Server.zip'
55+
- run: Compress-Archive -Path 'source/Server/bin/Release/net9.0/publish/*' -DestinationPath 'Server.zip'
5656
shell: pwsh
57-
- run: Compress-Archive -Path 'source/WebApp.Server/bin/Release/net8.0/publish/*' -DestinationPath 'WebApp.Server.zip'
57+
- run: Compress-Archive -Path 'source/WebApp.Server/bin/Release/net9.0/publish/*' -DestinationPath 'WebApp.Server.zip'
5858
shell: pwsh
5959

6060
- uses: actions/upload-artifact@v3
@@ -109,12 +109,12 @@ jobs:
109109
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
110110
runs-on: windows-latest
111111
steps:
112-
- uses: actions/checkout@v3
112+
- uses: actions/checkout@v4
113113
with:
114114
submodules: 'true'
115-
- uses: actions/setup-dotnet@v3
115+
- uses: actions/setup-dotnet@v4
116116
with:
117-
dotnet-version: 8.0.x
117+
dotnet-version: 9.0.x
118118

119119
# https://github.com/actions/setup-dotnet/issues/155
120120
- run: dotnet nuget locals all --clear
@@ -178,7 +178,7 @@ jobs:
178178
- deploy-netfx
179179
if: github.ref == 'refs/heads/main'
180180
steps:
181-
- uses: actions/checkout@v3
181+
- uses: actions/checkout@v4
182182

183183
- run: 'git show ${{ github.sha }} --format="version_number=%cd" --date=format:%Y-%m-%d-%H%M --no-patch >> $GITHUB_OUTPUT'
184184
id: version

Diff for: global.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.100",
3+
"version": "9.0.100",
44
"rollForward": "latestFeature"
55
}
66
}

Diff for: source/Container.Manager/Container.Manager.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFramework>net9.0</TargetFramework>
44
<AssemblyName>SharpLab.Container.Manager</AssemblyName>
55
<RootNamespace>SharpLab.Container.Manager</RootNamespace>
66
</PropertyGroup>

Diff for: source/Container.Warmup/Container.Warmup.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<AssemblyName>SharpLab.Container.Warmup</AssemblyName>
66
<RootNamespace>SharpLab.Container.Warmup</RootNamespace>
77
</PropertyGroup>

Diff for: source/Container/Container.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFramework>net9.0</TargetFramework>
44
<AssemblyName>SharpLab.Container</AssemblyName>
55
<RootNamespace>SharpLab.Container</RootNamespace>
66
<OutputType>Exe</OutputType>

Diff for: source/NetFramework/Server/Web.config

+6
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,11 @@
204204
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
205205
</dependentAssembly>
206206
</assemblyBinding>
207+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
208+
<dependentAssembly>
209+
<assemblyIdentity name="System.Security.AccessControl" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
210+
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
211+
</dependentAssembly>
212+
</assemblyBinding>
207213
</runtime>
208214
</configuration>

Diff for: source/Server/Server.csproj

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFramework>net9.0</TargetFramework>
44
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
55
<AssemblyName>SharpLab.Server</AssemblyName>
66
<RootNamespace>SharpLab.Server</RootNamespace>
@@ -46,6 +46,11 @@
4646
<PackageReference Include="Microsoft.ILVerification" Version="7.0.0-preview.4.22229.4" />
4747
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.2.0" />
4848
<PackageReference Include="Mono.Cecil" Version="0.11.4" />
49+
<!--
50+
Avoids vulnerability in version referenced by other dependencies
51+
TOOD: Try removing after upgrading Microsoft.Azure.Cosmos.Table.
52+
-->
53+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
4954
<PackageReference Include="Octokit" Version="0.32.0" />
5055
<PackageReference Include="Iced" Version="1.6.0" />
5156
<PackageReference Include="SharpYaml" Version="1.6.2" />

Diff for: source/Server/Startup.cs

+93-93
Original file line numberDiff line numberDiff line change
@@ -17,111 +17,111 @@
1717
using Microsoft.AspNetCore.Http;
1818
using System.Threading.Tasks;
1919

20-
namespace SharpLab.Server {
21-
public class Startup {
22-
// Chrome would limit to 10 mins I believe
23-
private static readonly TimeSpan CorsPreflightMaxAge = TimeSpan.FromHours(1);
24-
25-
public void ConfigureServices(IServiceCollection services) {
26-
services.AddHttpClient();
27-
services.AddCors();
28-
services.AddControllers();
29-
}
20+
namespace SharpLab.Server;
3021

31-
public void ConfigureContainer(ContainerBuilder builder) {
32-
var assembly = Assembly.GetExecutingAssembly();
22+
public class Startup {
23+
// Chrome would limit to 10 mins I believe
24+
private static readonly TimeSpan CorsPreflightMaxAge = TimeSpan.FromHours(1);
3325

34-
builder
35-
.RegisterAssemblyModulesInDirectoryOf(assembly)
36-
.WhereFileMatches("SharpLab.*");
37-
}
26+
public void ConfigureServices(IServiceCollection services) {
27+
services.AddHttpClient();
28+
services.AddCors();
29+
services.AddControllers();
30+
}
31+
32+
public void ConfigureContainer(ContainerBuilder builder) {
33+
var assembly = Assembly.GetExecutingAssembly();
34+
35+
builder
36+
.RegisterAssemblyModulesInDirectoryOf(assembly)
37+
.WhereFileMatches("SharpLab.*");
38+
}
3839

39-
public static MirrorSharpOptions CreateMirrorSharpOptions(ILifetimeScope container) {
40-
var options = new MirrorSharpOptions {
41-
IncludeExceptionDetails = true,
42-
StatusTestCommands = {
43-
('O', "x-optimize=debug,x-target=C#,x-no-cache=true,language=C#"),
44-
('R', "0:0:0::using System; public class C { public void M() { } }"),
45-
('U', "")
46-
}
47-
};
48-
var languages = container.Resolve<ILanguageAdapter[]>();
49-
foreach (var language in languages) {
50-
language.SlowSetup(options);
40+
public static MirrorSharpOptions CreateMirrorSharpOptions(ILifetimeScope container) {
41+
var options = new MirrorSharpOptions {
42+
IncludeExceptionDetails = true,
43+
StatusTestCommands = {
44+
('O', "x-optimize=debug,x-target=C#,x-no-cache=true,language=C#"),
45+
('R', "0:0:0::using System; public class C { public void M() { } }"),
46+
('U', "")
5147
}
52-
PerformanceLog.Checkpoint("Startup.CreateMirrorSharpOptions.End");
53-
return options;
48+
};
49+
var languages = container.Resolve<ILanguageAdapter[]>();
50+
foreach (var language in languages) {
51+
language.SlowSetup(options);
5452
}
53+
PerformanceLog.Checkpoint("Startup.CreateMirrorSharpOptions.End");
54+
return options;
55+
}
5556

56-
public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
57+
public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
58+
if (env.IsDevelopment())
59+
app.UseDeveloperExceptionPage();
60+
61+
app.UseRouting();
62+
app.UseCors(p => p
63+
.AllowAnyHeader()
64+
.AllowAnyOrigin()
65+
.AllowAnyMethod()
66+
.SetPreflightMaxAge(CorsPreflightMaxAge)
67+
);
68+
69+
app.UseWebSockets();
70+
app.MapMirrorSharp("/mirrorsharp", CreateMirrorSharpOptions(app.ApplicationServices.GetAutofacRoot()));
71+
72+
app.UseEndpoints(e => {
73+
MapStatus(e);
74+
MapBranchVersion(e, env);
5775
if (env.IsDevelopment())
58-
app.UseDeveloperExceptionPage();
59-
60-
app.UseRouting();
61-
app.UseCors(p => p
62-
.AllowAnyHeader()
63-
.AllowAnyOrigin()
64-
.AllowAnyMethod()
65-
.SetPreflightMaxAge(CorsPreflightMaxAge)
66-
);
67-
68-
app.UseWebSockets();
69-
app.MapMirrorSharp("/mirrorsharp", CreateMirrorSharpOptions(app.ApplicationServices.GetAutofacRoot()));
70-
71-
app.UseEndpoints(e => {
72-
MapStatus(e);
73-
MapBranchVersion(e, env);
74-
if (env.IsDevelopment())
75-
MapFeatureFlags(e);
76-
MapOtherEndpoints(e);
77-
78-
e.MapControllers();
79-
});
80-
}
76+
MapFeatureFlags(e);
77+
MapOtherEndpoints(e);
8178

82-
private void MapStatus(IEndpointRouteBuilder e) {
83-
var okBytes = new ReadOnlyMemory<byte>(Encoding.UTF8.GetBytes("OK"));
84-
e.MapGet("/status", context => {
85-
context.Response.ContentType = MediaTypeNames.Text.Plain;
86-
return WriteResponseBodyAsync(context, okBytes);
87-
});
88-
}
79+
e.MapControllers();
80+
});
81+
}
8982

90-
private void MapFeatureFlags(IEndpointRouteBuilder e) {
91-
e.MapGet("/featureflags/{key:alpha}", static context => {
92-
var key = (string)context.GetRouteValue("key")!;
93-
var featureFlagClient = context.RequestServices.GetRequiredService<IFeatureFlagClient>();
83+
private void MapStatus(IEndpointRouteBuilder e) {
84+
var okBytes = new ReadOnlyMemory<byte>(Encoding.UTF8.GetBytes("OK"));
85+
e.MapGet("/status", context => {
86+
context.Response.ContentType = MediaTypeNames.Text.Plain;
87+
return WriteResponseBodyAsync(context, okBytes);
88+
});
89+
}
9490

95-
return context.Response.WriteAsync(
96-
featureFlagClient.GetInt32Flag(key)?.ToString() ?? "<null>",
97-
context.RequestAborted
98-
);
99-
});
100-
}
91+
private void MapFeatureFlags(IEndpointRouteBuilder e) {
92+
e.MapGet("/featureflags/{key:alpha}", static context => {
93+
var key = (string)context.GetRouteValue("key")!;
94+
var featureFlagClient = context.RequestServices.GetRequiredService<IFeatureFlagClient>();
10195

102-
// Temporary: until build is updated to something better than a json file on site itself
103-
protected virtual void MapBranchVersion(IEndpointRouteBuilder endpoints, IWebHostEnvironment env) {
104-
var file = env.WebRootFileProvider.GetFileInfo("branch-version.json");
105-
if (!file.Exists)
106-
return;
107-
108-
using var stream = file.CreateReadStream();
109-
var bytes = new byte[stream.Length];
110-
stream.Read(bytes, 0, bytes.Length);
111-
endpoints.MapGet("/branch-version.json", context => {
112-
context.Response.ContentType = MediaTypeNames.Application.Json;
113-
return WriteResponseBodyAsync(context, bytes);
114-
});
115-
}
96+
return context.Response.WriteAsync(
97+
featureFlagClient.GetInt32Flag(key)?.ToString() ?? "<null>",
98+
context.RequestAborted
99+
);
100+
});
101+
}
116102

117-
private Task WriteResponseBodyAsync(HttpContext context, ReadOnlyMemory<byte> body) {
118-
var writeTask = context.Response.BodyWriter.WriteAsync(body, context.RequestAborted);
119-
return writeTask.IsCompletedSuccessfully
120-
? Task.CompletedTask
121-
: writeTask.AsTask();
122-
}
103+
// Temporary: until build is updated to something better than a json file on site itself
104+
protected virtual void MapBranchVersion(IEndpointRouteBuilder endpoints, IWebHostEnvironment env) {
105+
var file = env.WebRootFileProvider.GetFileInfo("branch-version.json");
106+
if (!file.Exists)
107+
return;
108+
109+
using var stream = file.CreateReadStream();
110+
var bytes = new byte[stream.Length];
111+
stream.ReadExactly(bytes, 0, bytes.Length);
112+
endpoints.MapGet("/branch-version.json", context => {
113+
context.Response.ContentType = MediaTypeNames.Application.Json;
114+
return WriteResponseBodyAsync(context, bytes);
115+
});
116+
}
123117

124-
protected virtual void MapOtherEndpoints(IEndpointRouteBuilder endpoints) {
125-
}
118+
private Task WriteResponseBodyAsync(HttpContext context, ReadOnlyMemory<byte> body) {
119+
var writeTask = context.Response.BodyWriter.WriteAsync(body, context.RequestAborted);
120+
return writeTask.IsCompletedSuccessfully
121+
? Task.CompletedTask
122+
: writeTask.AsTask();
123+
}
124+
125+
protected virtual void MapOtherEndpoints(IEndpointRouteBuilder endpoints) {
126126
}
127127
}

0 commit comments

Comments
 (0)