Skip to content

Commit 643b246

Browse files
committed
try to upgrade to .NET 10
Note after .NET 8 and upgrading to .NET 10 I found that the wwwroot\_framework\*.dll files now instead of being System.Private.CoreLib.dll it is System.Private.CoreLib.<hash>.dll breaking the compiling compatibility. Another option was to grab the DLLs from�C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\10.0.1\ref\net10.0 copy them and embed them with the assembly and extract them at runtime. There may be changes in future versions in .NET 11 or higher based on defaults for: compilation using AOT, single file publish, trimming For .NET 10 this should still work. So this should be good until 2028
1 parent 24962ee commit 643b246

File tree

4 files changed

+79
-14
lines changed

4 files changed

+79
-14
lines changed

.github/workflows/dotnet.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
# Checkout the code
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
1414

1515
# Install .NET Core SDK
1616
- name: Setup .NET Core
17-
uses: actions/setup-dotnet@v1
17+
uses: actions/setup-dotnet@v3
1818
with:
19-
dotnet-version: 8.0.200
19+
dotnet-version: 10.0.x
2020

2121
# Publish the site
2222
- name: Publish
23+
# First publish: generate framework_manifest.json
24+
# Don't missing to add "p:GHPages=true". 👇
25+
run: dotnet publish Ellabit/Ellabit.csproj -p:GHPages=true -o:public -c:Release
26+
27+
28+
# Second publish (embed json with correct framework files hashes)
2329
# Don't missing to add "p:GHPages=true". 👇
2430
run: dotnet publish Ellabit/Ellabit.csproj -p:GHPages=true -o:public -c:Release
2531

Ellabit/DynamicCode/SimpleUnloadableAssemblyLoadContext.cs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.CodeAnalysis;
1212
using Microsoft.CodeAnalysis.CSharp;
1313
using Microsoft.CodeAnalysis.Emit;
14+
using Newtonsoft.Json.Linq;
1415

1516
namespace Ellabit.DynamicCode
1617
{
@@ -21,8 +22,33 @@ public SimpleUnloadableAssemblyLoadContext(HttpClient httpClient)
2122
: base(isCollectible: true)
2223
{
2324
client = httpClient;
24-
}
25+
26+
var asm = Assembly.GetExecutingAssembly();
27+
using var stream = asm.GetManifestResourceStream("Ellabit.framework_manifest.json");
28+
using var reader = new StreamReader(stream!);
29+
var json = reader.ReadToEnd();
30+
if (string.IsNullOrEmpty(json))
31+
{
32+
System.Console.WriteLine("framework_manifest.json is empty");
33+
return;
34+
}
35+
36+
var frameworkAssemblyJson = JArray.Parse(json);
37+
foreach (JObject child in frameworkAssemblyJson)
38+
{
39+
string name = child["Name"]!.ToString();
40+
int lastDot = name.LastIndexOf('.');
41+
name = lastDot > 0 ? name.Substring(0, lastDot) : name;
42+
43+
string file = child["File"]!.ToString();
44+
lastDot = file.LastIndexOf('.');
45+
file = lastDot > 0 ? file.Substring(0, lastDot) : file;
46+
47+
References.Add(name, file);
48+
}
49+
}
2550
public IChallenge? Challenge { get; set; }
51+
public Dictionary<string, string> References { get; set; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
2652

2753
public void Dispose()
2854
{
@@ -197,8 +223,7 @@ public static (bool IsCompleted, object? Output) ExecuteWithTimeLimit(TimeSpan t
197223
}
198224
return assembly;
199225
}
200-
201-
226+
202227
private async Task<IEnumerable<Stream>> GetReferenceAssembliesStreamsAsync(IEnumerable<string> referenceAssemblyNames)
203228
{
204229
if (client == null)
@@ -210,19 +235,24 @@ private async Task<IEnumerable<Stream>> GetReferenceAssembliesStreamsAsync(IEnum
210235
await Task.WhenAll(
211236
referenceAssemblyNames.Select(async assemblyName =>
212237
{
213-
HttpResponseMessage? result = null;
238+
//Change assemblyName to assemblyNameWithHash
239+
string assemblyNameWithHash = References.ContainsKey(assemblyName) ? References[assemblyName] : assemblyName;
240+
241+
Console.WriteLine($"Loading reference assembly: {assemblyName} : {assemblyNameWithHash}");
242+
243+
HttpResponseMessage? result = null;
214244
bool hasError = false;
215245
try
216246
{
217-
result = await client.GetAsync($"/_framework/{assemblyName}.dll");
247+
result = await client.GetAsync($"/_framework/{assemblyNameWithHash}.dll");
218248

219249
result.EnsureSuccessStatusCode();
220250
}
221251
catch
222252
{
223253
try
224254
{
225-
result = await client.GetAsync($"/Ellabit/_framework/{assemblyName}.dll");
255+
result = await client.GetAsync($"/Ellabit/_framework/{assemblyNameWithHash}.dll");
226256

227257
result.EnsureSuccessStatusCode();
228258
}

Ellabit/Ellabit.csproj

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
@@ -14,10 +14,10 @@
1414

1515
<PackageReference Include="IronBlock" Version="1.0.18" />
1616

17-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.6" />
18-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.6" PrivateAssets="all" />
17+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.1" />
18+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.1" PrivateAssets="all" />
1919
<PackageReference Include="MudBlazor" Version="6.0.20" />
20-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
20+
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
2121
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.9.0" />
2222
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.9.0" />
2323
<PackageReference Include="BlazorMonaco" Version="2.1.0" />
@@ -79,4 +79,32 @@
7979
<ItemGroup>
8080
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
8181
</ItemGroup>
82-
</Project>
82+
83+
84+
85+
<Target Name="CreateFrameworkDllManifest" AfterTargets="Build">
86+
<PropertyGroup>
87+
<!-- Remove the last 'publish\' from PublishDir -->
88+
<PublishRootDir>$(PublishDir.Replace('publish\', ''))</PublishRootDir>
89+
</PropertyGroup>
90+
<!-- Get all DLLs in wwwroot/_framework -->
91+
<ItemGroup>
92+
<FrameworkDlls Include="$(PublishRootDir)\wwwroot\_framework\*.dll" />
93+
</ItemGroup>
94+
95+
<!-- debug -->
96+
<Warning Text="Generating framework_manifest.json with $(PublishRootDir)" Condition="true" />
97+
98+
<!-- Build JSON lines -->
99+
<WriteLinesToFile
100+
File="$(MSBuildProjectDirectory)\framework_manifest.json"
101+
Lines="@(FrameworkDlls->'{ &quot;Name&quot;: &quot;%(Filename)&quot;, &quot;File&quot;: &quot;%(Filename)%(Extension)&quot; }')"
102+
Overwrite="true" />
103+
104+
<!-- Optional: wrap lines in an array -->
105+
<Exec Command="powershell -Command &quot;$json = Get-Content '$(MSBuildProjectDirectory)\framework_manifest.json' -Raw; Set-Content '$(MSBuildProjectDirectory)\framework_manifest.json' ('[' + ($json -replace '(\r?\n)',' , ') + ']')&quot;" />
106+
</Target>
107+
<ItemGroup>
108+
<EmbeddedResource Include="framework_manifest.json" />
109+
</ItemGroup>
110+
</Project>

0 commit comments

Comments
 (0)