Skip to content

Conversation

@maraf
Copy link
Member

@maraf maraf commented Oct 22, 2025

Use WasmFilesToIncludeInFileSystem items to automatically load files to VFS when the application is starting.

The identity of WasmFilesToIncludeInFileSystem needs to be a relative path to files in wwwroot (either physical or linked). The optional TargetPath metadata allows to modify file location in VFS. If the metadata is omitted, a default location will be resolved from relative file path in wwwroot.

Example:

  • Having a wwwroot/file.txt file
    • <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.txt
  • Having a wwwroot/subdir/file.txt file
    • <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.txt
When `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

@maraf maraf added this to the 11.0.0 milestone Oct 22, 2025
@maraf maraf self-assigned this Oct 22, 2025
@maraf maraf added arch-wasm WebAssembly architecture area-Build-mono os-browser Browser variant of arch-wasm labels Oct 22, 2025
@maraf maraf marked this pull request as ready for review October 27, 2025 14:16
Copilot AI review requested due to automatic review settings October 27, 2025 14:16
Copy link
Contributor

Copilot AI left a 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

@maraf maraf requested a review from pavelsavara October 29, 2025 13:36
@maraf maraf enabled auto-merge (squash) October 29, 2025 13:36
@maraf
Copy link
Member Author

maraf commented Oct 30, 2025

/ba-g Failure is unrelated timeout

@maraf maraf merged commit ac7666f into dotnet:main Oct 31, 2025
32 of 34 checks passed
@maraf maraf deleted the WasmSdkVfs branch October 31, 2025 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Build-mono os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[wasm] VFS/common WasmApp properties ignored in wasmbrowser template

2 participants