Skip to content
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

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

Open
RedMike opened this issue Mar 4, 2024 · 6 comments
Open

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

RedMike opened this issue Mar 4, 2024 · 6 comments
Assignees
Labels
arch-wasm WebAssembly architecture area-Build-mono os-browser Browser variant of arch-wasm
Milestone

Comments

@RedMike
Copy link

RedMike commented Mar 4, 2024

Description

There are a number of public properties listed in WasmApp.Common.targets (previously WasmApp.targets) like WasmFilesToIncludeInFileSystem. However, at least in 8.0.2, the logic does not run even for a fresh project from wasmbrowser template. This seems to be because some properties/items are tied to WasmGenerateAppBundle being true (which leads to _WasmGenerateAppBundle running), but that is forced to false when _UsingBlazorOrWasmSdk is true within the toolchain.

This means that there's no actual AppBundle folder created, VFS isn't exposed at all so there's no apparent way to add files to it, and some other properties listed in the targets file don't seem to have an effect.

Setting WasmGenerateAppBundle to true, or attempting to unset _UsingBlazorOrWasmSdk, in the csproj does not work because these values are being set in the toolchain file.

The documentation for WasmGenerateAppBundle at least seems to be wrong if this is intentional:

Defaults to true.
This is useful for projects that want to handle their own
packaging, or app bundle generation, eg. Blazor.

But then also there's no exposed way to acccess VFS and a few other features, when it would be convenient to do so.
The documentation in features.md is also wrong then, as it lists AppBundle as the folder and that is never created from the template, only wwwroot.

Reproduction Steps

  1. Install wasm-tools and wasm-experimental workloads (to have the templates, but that's not strictly required I think)
  2. Create a project from the wasmbrowser template
  3. Enable MSBuild Detailed logging
  4. Build or publish the project

Expected behavior

Target _WasmGenerateAppBundle is not skipped.

Actual behavior

Target "_WasmGenerateAppBundle" skipped, due to false condition; ('$(WasmGenerateAppBundle)' == 'true') was evaluated as ('false' == 'true').

Regression?

No response

Known Workarounds

Injecting a target that runs as part of the toolchain or at least early enough in the WASM workflow, which sets WasmGenerateAppBundle works.

For VFS specifically, I understand there might be some way to provide a custom MonoConfig in JS to set a list of assets. I haven't been able to get that working because of errors during the build, which seem to be tied to the MSBuild targets expecting WasmAppBuilder to have run (which it doesn't).

Configuration

.NET 8
Browser WASM

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Mar 4, 2024
@kg kg added the arch-wasm WebAssembly architecture label Mar 4, 2024
@ghost
Copy link

ghost commented Mar 4, 2024

Tagging subscribers to 'arch-wasm': @lewing
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

There are a number of public properties listed in WasmApp.Common.targets (previously WasmApp.targets) like WasmFilesToIncludeInFileSystem. However, at least in 8.0.2, the logic does not run even for a fresh project from wasmbrowser template. This seems to be because some properties/items are tied to WasmGenerateAppBundle being true (which leads to _WasmGenerateAppBundle running), but that is forced to false when _UsingBlazorOrWasmSdk is true within the toolchain.

This means that there's no actual AppBundle folder created, VFS isn't exposed at all so there's no apparent way to add files to it, and some other properties listed in the targets file don't seem to have an effect.

Setting WasmGenerateAppBundle to true, or attempting to unset _UsingBlazorOrWasmSdk, in the csproj does not work because these values are being set in the toolchain file.

The documentation for WasmGenerateAppBundle at least seems to be wrong if this is intentional:

                                              This is useful for projects that want to handle their own
                                              packaging, or app bundle generation, eg. Blazor.```
But then also there's no exposed way to acccess VFS and a few other features, when it would be convenient to do so.

### Reproduction Steps

1. Install `wasm-tools` and `wasm-experimental` workloads (to have the templates, but that's not strictly required I think)
2. Create a project from the `wasmbrowser` template
3. Enable MSBuild Detailed logging
4. Build or publish the project

### Expected behavior

Target `_WasmGenerateAppBundle` is not skipped.

### Actual behavior

`Target "_WasmGenerateAppBundle" skipped, due to false condition; ('$(WasmGenerateAppBundle)' == 'true') was evaluated as ('false' == 'true').`

### Regression?

_No response_

### Known Workarounds

Injecting a target that runs as part of the toolchain or at least early enough in the WASM workflow, which sets `WasmGenerateAppBundle` works.

For VFS specifically, I understand there might be some way to provide a custom `MonoConfig` in JS to set a list of assets. I haven't been able to get that working because of errors during the build, which seem to be tied to the MSBuild targets expecting `WasmAppBuilder` to have run (which it doesn't).

### Configuration

.NET 8
Browser WASM

### Other information

_No response_

<table>
  <tr>
    <th align="left">Author:</th>
    <td>RedMike</td>
  </tr>
  <tr>
    <th align="left">Assignees:</th>
    <td>-</td>
  </tr>
  <tr>
    <th align="left">Labels:</th>
    <td>

`arch-wasm`, `untriaged`, `area-Build-mono`

</td>
  </tr>
  <tr>
    <th align="left">Milestone:</th>
    <td>-</td>
  </tr>
</table>
</details>

@RedMike
Copy link
Author

RedMike commented Mar 4, 2024

I thought it was weird that the tests hadn't caught this or at least had warnings, it looks like the tests have a warning for this:

<Warning
      Condition="'$(WasmMainJS)' != '' and '$(WasmGenerateAppBundle)' != 'true'"
      Text="%24(WasmMainJS) is set when %24(WasmGenerateAppBundle) is not true: it won't be used because an app bundle is not being generated. Possible build authoring error" />

But the element isn't WasmMainJS, it's WasmMainJSPath.

@maraf maraf self-assigned this Mar 4, 2024
@maraf maraf added this to the 9.0.0 milestone Mar 4, 2024
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Mar 4, 2024
@maraf maraf added the os-browser Browser variant of arch-wasm label Mar 4, 2024
@maraf
Copy link
Member

maraf commented Mar 4, 2024

The wasmbrowser template was migrated to a new SDK that is aligned with Blazor project layout and build.
Some of the properties are not supported in .NET 8. We are working on filling these gaps.

As a work around you have two options
a. You can put files that you need to download to VFS in wwwroot and then configure dotnet in JS

dotnet.withConfig({ resources: { vfs: { "virtual_path_file_in_vfs.txt": { "relative_path_in_wwwroot_to_file.txt" : null } } } })

b. Revert back to previous SDK (it fully works in .NET 8, but will be removed in the future)
You can generate a wasmconsole app and override content from runtimeconfig.template.json

@RedMike
Copy link
Author

RedMike commented Mar 4, 2024

Right, thanks, I was worried it might be something like that. Is there any info on what the plan is for the new SDK for these things (will VFS be used at all, how will we be able to add content to wwwroot from referenced projects, etc), or is it still being decided as things are developed?

I can build something to work around it with the first option, I just don't want to end up with something that's completely incompatible with how it's meant to work in .NET 9 and later, if there's already info.

@RedMike
Copy link
Author

RedMike commented Mar 4, 2024

Trying the workaround though, I still end up with runtime failures in JS: Assert failed: Expect to have one dotnetwasm asset in resources. Because I guess I'm overwriting the config instead of adding to it, that's why I thought I needed a build step that adds it as an asset (so the built blazor.boot.json is still read and used, we just add new elements under vfs which doesn't exist there).

I could load blazor.boot.json explicitly before dotnet.create(), parse it, add the vfs entries, and then send that to withConfig during the call. It feels a bit brittle but I guess it works.

Confirmed this works (looked it up in the advanced sample in dotnet/runtime):

    .withModuleConfig({
            onConfigLoaded: (config) => {
                if (!config.resources.vfs) {
                    config.resources.vfs = {}
                }
                config.resources.vfs["img/test1.png"] = {"../img/test1.png": null} //.. is because the default path starts at /_framework, not wwwroot
            },
        })
    .create();

@maraf
Copy link
Member

maraf commented Mar 4, 2024

Sorry, I missed that we are checking just presence of resources in manual config to decide whether to load boot.json

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

No branches or pull requests

3 participants