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

Browser StaticWebAssets sdk support #14225

Merged
merged 9 commits into from
Feb 11, 2024
Merged

Conversation

maxkatz6
Copy link
Member

What does the pull request do?

In short, StaticWebAssets SDK allows to use caching and compression implemented on the SDK level, but only for .NET 8 apps. But we still can make our .NET 7 target compatible with that. Unfortunately, not without minor breaking changes (see below).

How was the solution implemented (if it's not obvious)?

  1. Changes Avalonia.Browser nupkg structure to match typical WebAssembly+StaticWebAssets library.
  2. Adds Microsoft.AspNetCore.StaticWebAssets.props file to the Avalonia.Browser nupkg that includes StaticWebAsset items. Note: we still keep legacy (non-StaticWebAssets) items set by WasmExtraFilesToDeploy.
  3. Removes old hacks from the blazor project, as now both use StaticWebAssets.
  4. Removes "WasmRuntimeAssetsLocation" property override. StaticWebAssets SDK ignores it, so we can't really override "_framework" there reliably.
  5. Fixes Browser lifetime issue (Browser was broken on the master branch)
  6. Removes 'WebEmbeddableControlRoot" hack as we don't need it anymore.

Breaking changes

All .NET 8 WASM project will need to set "WasmRuntimeAssetsLocation" to "./" value.
Or, if they want to switch to StaticWebAssets (and gain some of its features, like compression or caching), they can do a simple migration:

  1. Move all their JS/HTML files from old "AppBundle" folder to a new "wwwroot". (.NET SDK doesn't allow reconfiguring it).
  2. In "main.js" replace from import { dotnet } from './dotnet.js' to import { dotnet } from './_framework/dotnet.js'.
  3. In "csproj" replace from <Project Sdk="Microsoft.NET.Sdk"> to <Project Sdk="Microsoft.NET.Sdk.WebAssembly">.
  4. Remove "WasmMainJSPath" and "RuntimeIdentifier" from the csproj as well (not necessary anymore).

.NET WebAssembly templates already use Microsoft.NET.Sdk.WebAssembly SDK (which includes StaticWebAssets
SDK), so these can be used as an example:
https://github.com/dotnet/runtime/tree/main/src/mono/wasm/templates/templates/browser

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0043622-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 enabled auto-merge February 11, 2024 07:54
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.1.999-cibuild0044803-beta. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 added this pull request to the merge queue Feb 11, 2024
Merged via the queue into master with commit 0c0d449 Feb 11, 2024
6 checks passed
@maxkatz6 maxkatz6 deleted the static-web-assets-sdk-support branch February 11, 2024 15:11
maxkatz6 added a commit that referenced this pull request Feb 14, 2024
* Property support StaticWebAssets SDK when it's available

* Fix browser issue with dispatcher used before initialization

* Use RequestAnimationFrame instead of WebEmbeddableControlRoot hack

* Always include both types of assets by default, as I couldn't find a reliable way to detect project capabilities properly

* Remove "WasmRuntimeAssetsLocation" override, instead let users use default value set by .NET SDK

* Revert "Fix browser issue with dispatcher used before initialization"

This reverts commit fc43c7e.

* Add AvaloniaAllowWebGl2 prop

* What
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants