-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[browser] Support WasmFilesToIncludeInFileSystem in WasmSdk #120970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonBuilderHelper.cs
Show resolved
Hide resolved
VFS imports were incorrectly generated as "es module" imports, where as they should be treated as "general URL" imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements support for automatically loading files into the WebAssembly Virtual File System (VFS) using the WasmFilesToIncludeInFileSystem item in the WasmSdk. Files specified with this item are loaded into VFS at application startup, with support for custom target paths via TargetPath metadata.
Key Changes:
- Added VFS resource support in boot JSON generation to handle files marked with
vfs:trait - Updated bundler-friendly mode to correctly reference VFS assets with relative paths
- Implemented target path resolution with fallback to file's wwwroot relative path
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/tasks/WasmAppBuilder/WasmAppBuilder.cs |
Updated virtual path prefix to respect RuntimeAssetsLocation |
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs |
Added VFS resource handling in boot config generation |
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonBuilderHelper.cs |
Fixed VFS asset path generation for bundler-friendly mode |
src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/subdir/subsubdir/Vfs3.txt |
Test file for nested VFS path without custom TargetPath |
src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/subdir/Vfs2.txt |
Test file for VFS with custom TargetPath |
src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js |
Added test scenario entry point |
src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/Vfs1.txt |
Test file for root-level VFS with custom TargetPath |
src/mono/wasm/testassets/WasmBasicTestApp/App/WasmBasicTestApp.csproj |
Added WasmFilesToIncludeInFileSystem declarations for testing |
src/mono/wasm/testassets/WasmBasicTestApp/App/FilesToIncludeInFileSystemTest.cs |
Test code to verify VFS file existence |
src/mono/wasm/testassets/JavascriptBundlers/rollup.config.mjs |
Updated rollup to handle .txt files |
src/mono/wasm/Wasm.Build.Tests/FilesToIncludeInFileSystemTests.cs |
Integration test for VFS functionality |
src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets |
MSBuild integration for WasmFilesToIncludeInFileSystem |
eng/testing/scenarios/BuildWasmAppsJobsList.txt |
Registered new test class for CI |
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs
Show resolved
Hide resolved
src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonBuilderHelper.cs
Show resolved
Hide resolved
...nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets
Outdated
Show resolved
Hide resolved
…sing WasmFilesToIncludeInFileSystem
|
/ba-g Failure is unrelated timeout |
Use
WasmFilesToIncludeInFileSystemitems to automatically load files to VFS when the application is starting.The identity of
WasmFilesToIncludeInFileSystemneeds to be a relative path to files inwwwroot(either physical or linked). The optionalTargetPathmetadata allows to modify file location in VFS. If the metadata is omitted, a default location will be resolved from relative file path inwwwroot.Example:
wwwroot/file.txtfile<WasmFilesToIncludeInFileSystem Include="file.txt" />will load the file to/file.txt<WasmFilesToIncludeInFileSystem Include="file.txt" TargetPath="/mydata/file.txt" />will load the file to/mydata/file.txtwwwroot/subdir/file.txtfile<WasmFilesToIncludeInFileSystem Include="subdir/file.txt" />will load the file to/subdir/file.txt<WasmFilesToIncludeInFileSystem Include="subdir/file.txt" TargetPath="/mydata/file.txt" />will load the file to/mydata/file.txtWhen `WasmFilesToIncludeInFileSystem` item is missing in StaticWebAssets, build fails (example output)
/workspaces/runtime/artifacts/bin/Wasm.Build.Tests/Debug/net10.0/linux-x64/wbtartifacts/nuget/SatelliteLoadingTestsFromReference_Release_False_st4zw1nv_xij/microsoft.net.sdk.webassembly.pack/10.0.0-dev/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets(353,5): error : Some of the 'WasmFilesToIncludeInFileSystem' where not found in StaticWebAssets. WasmFilesToIncludeInFileSystem: Vfs1.txt;subdir/Vfs2.txt;subdir/subsubdir/Vfs3.txt;NonExistent.txt, matched StaticWebAssets: /workspaces/runtime/artifacts/bin/Wasm.Build.Tests/Debug/net10.0/linux-x64/wbtartifacts/SatelliteLoadingTestsFromReference_Release_False_st4zw1nv_xij/App/wwwroot/Vfs1.txt;/workspaces/runtime/artifacts/bin/Wasm.Build.Tests/Debug/net10.0/linux-x64/wbtartifacts/SatelliteLoadingTestsFromReference_Release_False_st4zw1nv_xij/App/wwwroot/subdir/Vfs2.txt;/workspaces/runtime/artifacts/bin/Wasm.Build.Tests/Debug/net10.0/linux-x64/wbtartifacts/SatelliteLoadingTestsFromReference_Release_False_st4zw1nv_xij/App/wwwroot/subdir/subsubdir/Vfs3.txt [/workspaces/runtime/artifacts/bin/Wasm.Build.Tests/Debug/net10.0/linux-x64/wbtartifacts/SatelliteLoadingTestsFromReference_Release_False_st4zw1nv_xij/App/WasmBasicTestApp.csproj]Fixes #99223