Host and deploy ASP.NET Core standalone Blazor WebAssembly with GitHub Pages (original) (raw)

Important

This information relates to a pre-release product that may be substantially modified before it's commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

For the current release, see the .NET 9 version of this article.

This article explains how to host and deploy standalone Blazor WebAssembly using GitHub Pages.

The following guidance for GitHub Pages deployments of Blazor WebAssembly apps demonstrates concepts with a live tool deployed to GitHub Pages. The tool is used by the ASP.NET Core documentation authors to create cross-reference (XREF) links to API documentation for article markdown:

GitHub Pages settings

†The SHA hash ({SHA HASH} placeholder) represents the SHA hash for the latest stevesandersonms/ghaction-rewrite-base-href GitHub Action release version. By pinning to a specific version, there's less risk that a compromised latest release using a version moniker, such as v1, can jeopardize the deployment. Periodically, update the SHA to the latest release for the latest features and bug fixes.

To obtain the SHA hash:

  1. Navigate to the SteveSandersonMS/ghaction-rewrite-base-href Action GitHub repository.
  2. Select the release on the right-side of the page under Releases.
  3. Locate and select the short SHA hash (for example, 5b54862).
  4. Either:
    • Take the full SHA from the URL in the browser's address bar.
    • Select the copy button on the right side of page Copy button to put the SHA on your clipboard.

For more information, see Using pre-written building blocks in your workflow: Using SHAs (GitHub documentation).

Static deployment script configuration

Xref Generator static.yml file

Configure the following entries in the script for your deployment:

The GitHub-hosted Ubuntu (latest) server has a version of the .NET SDK pre-installed. You can remove the actions/setup-dotnet Action step from the static.yml script if the pre-installed .NET SDK is sufficient to compile the app. To determine the .NET SDK installed for ubuntu-latest:

  1. Go to the Available Images section of the actions/runner-images GitHub repository.
  2. Locate the ubuntu-latest image, which is the first table row.
  3. Select the link in the Included Software column.
  4. Scroll down to the .NET Tools section to see the .NET Core SDK installed with the image.

Deployment notes

The default GitHub Action, which deploys pages, skips deployment of folders starting with underscore, the _framework folder for example. To deploy folders starting with underscore, add an empty .nojekyll file to the root of the app's repository. Example: Xref Generator .nojekyll file

Perform this step before the first app deployment: Git treats JavaScript (JS) files, such as blazor.webassembly.js, as text and converts line endings from CRLF (carriage return-line feed) to LF (line feed) in the deployment pipeline. These changes to JS files produce different file hashes than Blazor sends to the client. The mismatches result in integrity check failures on the client. One approach to solving this problem is to add a .gitattributes file with *.js binary line before adding the app's assets to the Git branch. The *.js binary line configures Git to treat JS files as binary files, which avoids processing the files in the deployment pipeline and results in client-side integrity checks passing. For more information, see ASP.NET Core Blazor WebAssembly .NET bundle caching and integrity check failures. Example: Xref Generator .gitattributes file

To handle URL rewrites based on Single Page Apps for GitHub Pages (rafrex/spa-github-pages GitHub repository):

GitHub Pages doesn't natively support using Brotli-compressed resources. To use Brotli: