Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cc97de8

Browse files
committed
Bundle blazor.web.js in CI and simplify csproj
Add CI steps (verso-ci and verso-release) to extract blazor.web.js from the .NET 8 Components.Endpoints.dll into src/Verso.Cli/bin/Release/net8.0/wwwroot/_framework so the CLI tool bundles the script even when the runtime rolls forward. Update Verso.Cli.csproj: change RollForward from LatestMajor to Major, remove the RoslynCodeTaskFactory inline extraction fallback, and replace it with a simpler target that copies the NuGet-cached blazor.web.js into the output path and emits a warning if the file is not found. These changes ensure the tool package contains the required blazor.web.js for "verso serve" across runtime roll-forwards.
1 parent 00bb71d commit cc97de8

3 files changed

Lines changed: 54 additions & 45 deletions

File tree

.github/workflows/verso-ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,28 @@ jobs:
102102
8.0.x
103103
10.0.x
104104
105+
- name: Bundle blazor.web.js for CLI
106+
run: |
107+
DIR="src/Verso.Cli/bin/Release/net8.0/wwwroot/_framework"
108+
mkdir -p "$DIR"
109+
DLL=$(find "$DOTNET_ROOT/shared/Microsoft.AspNetCore.App" \
110+
-path "*/8.*/Microsoft.AspNetCore.Components.Endpoints.dll" | head -1)
111+
if [ -z "$DLL" ]; then
112+
echo "::warning::Could not find .NET 8 Components.Endpoints.dll"
113+
exit 0
114+
fi
115+
dotnet new console -o /tmp/_ebjs --no-restore -f net8.0
116+
cat > /tmp/_ebjs/Program.cs << 'EOF'
117+
var asm = System.Reflection.Assembly.LoadFrom(args[0]);
118+
using var s = asm.GetManifestResourceStream("_framework/blazor.web.js");
119+
if (s == null) { Console.Error.WriteLine("Resource not found"); return; }
120+
Directory.CreateDirectory(Path.GetDirectoryName(args[1])!);
121+
using var f = File.Create(args[1]);
122+
s.CopyTo(f);
123+
Console.WriteLine($"Extracted blazor.web.js ({f.Length} bytes)");
124+
EOF
125+
dotnet run --project /tmp/_ebjs -- "$DLL" "$DIR/blazor.web.js"
126+
105127
- name: Build
106128
run: dotnet build Verso.sln -c Release
107129

.github/workflows/verso-release.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,31 @@ jobs:
3838
8.0.x
3939
10.0.x
4040
41+
- name: Bundle blazor.web.js for CLI
42+
run: |
43+
# blazor.web.js is embedded in Components.Endpoints.dll in .NET 8/9
44+
# but not in .NET 10+. Extract it so verso serve works when the tool
45+
# rolls forward to a runtime that no longer bundles the script.
46+
DIR="src/Verso.Cli/bin/Release/net8.0/wwwroot/_framework"
47+
mkdir -p "$DIR"
48+
DLL=$(find "$DOTNET_ROOT/shared/Microsoft.AspNetCore.App" \
49+
-path "*/8.*/Microsoft.AspNetCore.Components.Endpoints.dll" | head -1)
50+
if [ -z "$DLL" ]; then
51+
echo "::warning::Could not find .NET 8 Components.Endpoints.dll"
52+
exit 0
53+
fi
54+
dotnet new console -o /tmp/_ebjs --no-restore -f net8.0
55+
cat > /tmp/_ebjs/Program.cs << 'EOF'
56+
var asm = System.Reflection.Assembly.LoadFrom(args[0]);
57+
using var s = asm.GetManifestResourceStream("_framework/blazor.web.js");
58+
if (s == null) { Console.Error.WriteLine("Resource not found"); return; }
59+
Directory.CreateDirectory(Path.GetDirectoryName(args[1])!);
60+
using var f = File.Create(args[1]);
61+
s.CopyTo(f);
62+
Console.WriteLine($"Extracted blazor.web.js ({f.Length} bytes)");
63+
EOF
64+
dotnet run --project /tmp/_ebjs -- "$DLL" "$DIR/blazor.web.js"
65+
4166
- name: Build
4267
run: dotnet build Verso.sln -c Release -p:Version=${{ steps.version.outputs.version }}
4368

src/Verso.Cli/Verso.Cli.csproj

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<RootNamespace>Verso.Cli</RootNamespace>
1010
<PackAsTool>true</PackAsTool>
1111
<ToolCommandName>verso</ToolCommandName>
12-
<RollForward>LatestMajor</RollForward>
12+
<RollForward>Major</RollForward>
1313
<PackageId>Verso.Cli</PackageId>
1414
<PackageDescription>Command-line tool for the Verso interactive notebook platform.</PackageDescription>
1515
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -24,57 +24,19 @@
2424
<FrameworkReference Include="Microsoft.AspNetCore.App" />
2525
</ItemGroup>
2626

27-
<!-- Locate blazor.web.js so it can be bundled with the tool.
28-
.NET 10+ ships it as a NuGet static web asset; .NET 8/9 embed it
29-
inside Microsoft.AspNetCore.Components.Endpoints.dll. We try the
30-
NuGet package first (MSBuild glob), then fall back to extracting the
31-
embedded resource via a small inline task. -->
32-
<UsingTask TaskName="_ExtractEmbeddedBlazorJs"
33-
TaskFactory="RoslynCodeTaskFactory"
34-
AssemblyFile="$(MSBuildToolsPath)/Microsoft.Build.Tasks.Core.dll">
35-
<ParameterGroup>
36-
<SharedFrameworkDir ParameterType="System.String" Required="true" />
37-
<OutputFile ParameterType="System.String" Required="true" />
38-
</ParameterGroup>
39-
<Task>
40-
<Code Type="Fragment" Language="cs"><![CDATA[
41-
var dll = System.IO.Path.Combine(SharedFrameworkDir, "Microsoft.AspNetCore.Components.Endpoints.dll");
42-
if (!System.IO.File.Exists(dll)) return true;
43-
try
44-
{
45-
var asm = System.Reflection.Assembly.LoadFrom(dll);
46-
using var stream = asm.GetManifestResourceStream("_framework/blazor.web.js");
47-
if (stream == null) return true;
48-
var dir = System.IO.Path.GetDirectoryName(OutputFile);
49-
if (!System.IO.Directory.Exists(dir)) System.IO.Directory.CreateDirectory(dir);
50-
using var fs = System.IO.File.Create(OutputFile);
51-
stream.CopyTo(fs);
52-
}
53-
catch { }
54-
return true;
55-
]]></Code>
56-
</Task>
57-
</UsingTask>
58-
59-
<Target Name="_ExtractBlazorFrameworkJs" AfterTargets="Build">
60-
<!-- Try NuGet package first (.NET 10+) -->
27+
<!-- blazor.web.js is placed into $(OutputPath)wwwroot/_framework/ before
28+
build by CI (see .github/workflows) or by the NuGet-cache copy below.
29+
The pack target then bundles it into the tool package. -->
30+
<Target Name="_CopyBlazorFrameworkJs" AfterTargets="Build">
6131
<ItemGroup>
6232
<_BlazorWebJsFromNuGet Include="$(NuGetPackageRoot)microsoft.aspnetcore.app.internal.assets/*/_framework/blazor.web.js" />
6333
</ItemGroup>
6434
<Copy SourceFiles="@(_BlazorWebJsFromNuGet)"
6535
DestinationFolder="$(OutputPath)wwwroot/_framework/"
6636
SkipUnchangedFiles="true"
6737
Condition="'@(_BlazorWebJsFromNuGet)' != ''" />
68-
<!-- Fallback: extract embedded resource (.NET 8/9 shared framework) -->
69-
<ItemGroup Condition="'@(_BlazorWebJsFromNuGet)' == ''">
70-
<_AspNetSharedFx Include="$(NetCoreRoot)shared/Microsoft.AspNetCore.App/*" />
71-
</ItemGroup>
72-
<_ExtractEmbeddedBlazorJs
73-
SharedFrameworkDir="%(_AspNetSharedFx.Identity)"
74-
OutputFile="$(OutputPath)wwwroot/_framework/blazor.web.js"
75-
Condition="'@(_BlazorWebJsFromNuGet)' == '' AND '@(_AspNetSharedFx)' != '' AND !Exists('$(OutputPath)wwwroot/_framework/blazor.web.js')" />
76-
<Warning Text="Could not locate blazor.web.js; verso serve may not function correctly."
77-
Condition="!Exists('$(OutputPath)wwwroot/_framework/blazor.web.js')" />
38+
<Warning Text="blazor.web.js not found in NuGet cache or $(OutputPath)wwwroot/_framework/. Run the extract-blazor-js CI step or copy the file manually."
39+
Condition="'@(_BlazorWebJsFromNuGet)' == '' AND !Exists('$(OutputPath)wwwroot/_framework/blazor.web.js')" />
7840
</Target>
7941

8042
<!-- Bundle static web assets so the Blazor Server app works when installed

0 commit comments

Comments
 (0)