Skip to content

Commit bc77f35

Browse files
2018Zexewjaredpar
andauthored
Add net100 web support (#83)
* Add .NET 10.0 Web support * Add .NET 10.0 Web support including generator changes and project file * Add .NET 100 Wasm reference assemblies * Fix WASM CoreLib discovery and update UnitTests TestData * Fixed string indentation and removed unnecessary project reference * Apply suggestions from code review Co-authored-by: Jared Parsons <jared@paranoidcoding.org> --------- Co-authored-by: Jared Parsons <jared@paranoidcoding.org>
1 parent c475a31 commit bc77f35

8 files changed

Lines changed: 6027 additions & 16 deletions

File tree

Basic.Reference.Assemblies.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<Project Path="Src/Basic.Reference.Assemblies.AspNet110/Basic.Reference.Assemblies.AspNet110.csproj" />
99
<Project Path="Src/Basic.Reference.Assemblies.AspNet80/Basic.Reference.Assemblies.AspNet80.csproj" />
1010
<Project Path="Src/Basic.Reference.Assemblies.AspNet90/Basic.Reference.Assemblies.AspNet90.csproj" />
11+
<Project Path="Src/Basic.Reference.Assemblies.Net100.Wasm/Basic.Reference.Assemblies.Net100.Wasm.csproj" />
1112
<Project Path="Src/Basic.Reference.Assemblies.Net100/Basic.Reference.Assemblies.Net100.csproj" />
1213
<Project Path="Src/Basic.Reference.Assemblies.Net110/Basic.Reference.Assemblies.Net110.csproj" />
1314
<Project Path="Src/Basic.Reference.Assemblies.Net20/Basic.Reference.Assemblies.Net20.csproj" />
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netstandard2.0</TargetFramework>
4+
<IsPackable>true</IsPackable>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageDownload Include="Microsoft.NETCore.App.Runtime.Mono.browser-wasm" Version="[10.0.7]" />
9+
</ItemGroup>
10+
11+
<Import Project="Generated.targets" />
12+
</Project>

Src/Basic.Reference.Assemblies.Net100.Wasm/Generated.cs

Lines changed: 5271 additions & 0 deletions
Large diffs are not rendered by default.

Src/Basic.Reference.Assemblies.Net100.Wasm/Generated.targets

Lines changed: 692 additions & 0 deletions
Large diffs are not rendered by default.

Src/Basic.Reference.Assemblies.UnitTests/Basic.Reference.Assemblies.UnitTests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
<ProjectReference Include="..\Basic.Reference.Assemblies.Net80\Basic.Reference.Assemblies.Net80.csproj" />
2626
<ProjectReference Include="..\Basic.Reference.Assemblies.Net80Windows\Basic.Reference.Assemblies.Net80Windows.csproj" />
2727
<ProjectReference Include="..\Basic.Reference.Assemblies.Net90\Basic.Reference.Assemblies.Net90.csproj" />
28+
<ProjectReference Include="..\Basic.Reference.Assemblies.Net100.Wasm\Basic.Reference.Assemblies.Net100.Wasm.csproj">
29+
<Aliases>Net100Wasm</Aliases>
30+
</ProjectReference>
2831
<ProjectReference Include="..\Basic.Reference.Assemblies.AspNet80\Basic.Reference.Assemblies.AspNet80.csproj" />
2932
<ProjectReference Include="..\Basic.Reference.Assemblies.NetCoreApp31\Basic.Reference.Assemblies.NetCoreApp31.csproj" />
3033
<ProjectReference Include="..\Basic.Reference.Assemblies.NetStandard13\Basic.Reference.Assemblies.NetStandard13.csproj" />

Src/Basic.Reference.Assemblies.UnitTests/SanityUnitTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
extern alias Net100Wasm;
2+
13
using Microsoft.CodeAnalysis;
24
using Microsoft.CodeAnalysis.CSharp;
35
using System;
@@ -8,6 +10,8 @@
810
using Xunit.Abstractions;
911
using Xunit.Sdk;
1012

13+
using Net100WasmAssembly = Net100Wasm::Basic.Reference.Assemblies.Net100Wasm;
14+
1115
namespace Basic.Reference.Assemblies.UnitTests;
1216

1317
public class SanityUnitTests(ITestOutputHelper outputHelper)
@@ -121,6 +125,7 @@ public void ReferencesLazyInit()
121125
Assert.NotEmpty(NetStandard13.References.All);
122126
Assert.NotEmpty(Net461.References.All);
123127
Assert.NotEmpty(Net472.References.All);
128+
Assert.NotEmpty(Net100WasmAssembly.References.All);
124129
}
125130

126131
[Fact]
@@ -210,5 +215,6 @@ public void LoadAll()
210215
Net461.References.All.ToList();
211216
Net40.References.All.ToList();
212217
Net70.References.All.ToList();
218+
Net100WasmAssembly.References.All.ToList();
213219
}
214220
}

Src/Basic.Reference.Assemblies.UnitTests/TestData.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
extern alias Combined;
2+
extern alias Net100Wasm;
3+
24

35
using System.Collections.Generic;
46
using System.Linq;
57

68
using CombinedAssembly = Combined::Basic.Reference.Assemblies;
9+
using Net100WasmAssembly = Net100Wasm::Basic.Reference.Assemblies.Net100Wasm;
710

811
namespace Basic.Reference.Assemblies.UnitTests
912
{
@@ -29,6 +32,7 @@ public static IEnumerable<object[]> ApplicationReferences
2932
new object[] { "net8.0", CombinedAssembly.Net80.References.All },
3033
new object[] { "net8.0", AspNet80.References.All },
3134
new object[] { "net9.0", Net90.References.All },
35+
new object[] { "net10.0-wasm", Net100WasmAssembly.References.All },
3236
};
3337
}
3438
}
@@ -71,6 +75,7 @@ public static IEnumerable<object[]> AllValues
7175
new object[] { "net7.0", Net70.ReferenceInfos.AllValues },
7276
new object[] { "net8.0", Net80.ReferenceInfos.AllValues },
7377
new object[] { "net9.0", Net90.ReferenceInfos.AllValues },
78+
new object[] { "net10.0-wasm", Net100WasmAssembly.ReferenceInfos.AllValues },
7479

7580
new object[] { "netstandard2.0", CombinedAssembly.NetStandard20.ReferenceInfos.AllValues },
7681
new object[] { "net472", CombinedAssembly.Net472.ReferenceInfos.AllValues },

Src/Generate/Program.cs

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Net80Windows();
1818
Net90();
1919
Net100();
20+
Net100Wasm();
2021
Net110();
2122
AspNet80();
2223
AspNet90();
@@ -108,6 +109,15 @@ void Net100()
108109
File.WriteAllText(Path.Combine(targetDir, "Generated.targets"), content.TargetsContent, encoding);
109110
}
110111

112+
void Net100Wasm()
113+
{
114+
var content = GetGeneratedContent("Net100Wasm", [@"microsoft.netcore.app.runtime.mono.browser-wasm/10.0.7/runtimes/browser-wasm/lib/net10.0"]);
115+
var targetDir = Path.Combine(srcPath, "Basic.Reference.Assemblies.Net100.Wasm");
116+
Directory.CreateDirectory(targetDir);
117+
File.WriteAllText(Path.Combine(targetDir, "Generated.cs"), content.CodeContent, encoding);
118+
File.WriteAllText(Path.Combine(targetDir, "Generated.targets"), content.TargetsContent, encoding);
119+
}
120+
111121
void Net110()
112122
{
113123
var content = GetGeneratedContent("Net110", [@"microsoft.netcore.app.ref/11.0.0-preview.3.26207.106/ref/net11.0"]);
@@ -591,31 +601,42 @@ public static ImmutableArray<PortableExecutableReference> All
591601
}
592602
""");
593603
}
604+
}
594605

595-
static IEnumerable<(string FilePath, string RelativeFilePath, Guid Mvid)> FindDlls(string[] packagePaths, string packagePrefix)
606+
static IEnumerable<(string FilePath, string RelativeFilePath, Guid Mvid)> FindDlls(string[] packagePaths, string packagePrefix)
607+
{
608+
var dllPaths = new List<string>();
609+
foreach (var packagePath in packagePaths)
596610
{
597-
var dllPaths = new List<string>();
598-
foreach (var packagePath in packagePaths)
611+
dllPaths.AddRange(Directory.GetFiles(packagePath, "*.dll"));
612+
613+
var facadesPath = Path.Combine(packagePath, "Facades");
614+
if (Directory.Exists(facadesPath))
599615
{
600-
dllPaths.AddRange(Directory.GetFiles(packagePath, "*.dll"));
601-
var facadesPath = Path.Combine(packagePath, "Facades");
602-
if (Directory.Exists(facadesPath))
603-
{
604-
dllPaths.AddRange(Directory.GetFiles(facadesPath, "*.dll"));
605-
}
616+
dllPaths.AddRange(Directory.GetFiles(facadesPath, "*.dll"));
606617
}
607-
608-
var allPropNames = new List<string>();
609-
foreach (var dllPath in dllPaths)
618+
619+
var nativePath = Path.GetFullPath(Path.Combine(packagePath, "..", "..", "native"));
620+
if (Directory.Exists(nativePath))
610621
{
611-
if (GetMvid(dllPath) is not var (mvid, isAssembly) || !isAssembly)
622+
var coreLibPath = Path.Combine(nativePath, "System.Private.CoreLib.dll");
623+
if (File.Exists(coreLibPath) && !dllPaths.Contains(coreLibPath))
612624
{
613-
continue;
625+
dllPaths.Add(coreLibPath);
614626
}
627+
}
628+
}
615629

616-
var relativeFilePath = dllPath.Substring(packagePrefix.Length);
617-
yield return (dllPath, relativeFilePath, mvid);
630+
var allPropNames = new List<string>();
631+
foreach (var dllPath in dllPaths)
632+
{
633+
if (GetMvid(dllPath) is not var (mvid, isAssembly) || !isAssembly)
634+
{
635+
continue;
618636
}
637+
638+
var relativeFilePath = dllPath.Substring(packagePrefix.Length);
639+
yield return (dllPath, relativeFilePath, mvid);
619640
}
620641
}
621642

0 commit comments

Comments
 (0)