---
title: "Publish a C# WebAssembly app to static hosting"
url: https://recursiveai.org/oneapp/cookbook/publish-oneapp-webassembly-to-static-host/
description: "Package a OneApp WebAssembly build, upload the folder to a static host, and serve .wasm files with the application/wasm content type."
version: "1.2.1"
---

No .NET server is needed.

```shell
dotnet tool install -g RecursiveAI.OneApp.Cli
dotnet workload install wasm-tools
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```shell
oneapp package . --format web --output ../dist
```

[The example](https://recursiveai.org/oneapp/cookbook/publish-oneapp-webassembly-to-static-host/publish-oneapp-webassembly-to-static-host.zip) is the full program below: unzip it and `dotnet run`.

Use `dotnet run` to preview the example locally, not to publish it.

Run `oneapp package` from the browser project folder (or the unzipped example).
It prints JSON: upload the contents of the directory named in its `folder` field.
For this example, that directory is `../dist/StageDemo-1.0.0-web/`.
Keep `_framework/` beside `index.html` and serve `.wasm` as `application/wasm`.

## Full program

The zip includes `StageDemo.csproj`, a `Microsoft.NET.Sdk.WebAssembly` project.
OneUI is the package that compiles `StageMessage.html` into C#.
For your own project, use `dotnet add package RecursiveAI.OneApp.Browser`
and `dotnet add package RecursiveAI.OneUI`:

```xml
<Project Sdk="Microsoft.NET.Sdk.WebAssembly">
  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <WasmFingerprintAssets>false</WasmFingerprintAssets>
    <InvariantGlobalization>true</InvariantGlobalization>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="RecursiveAI.OneApp.Browser" Version="1.2.1" />
    <PackageReference Include="RecursiveAI.OneUI" Version="1.2.1" />
  </ItemGroup>
</Project>
```

`Program.cs` registers the HTML tag. OneUI generates the other half of `StageMessage` from the template:

```csharp
using OneApp.Browser;
using System.Runtime.Versioning;

[assembly: SupportedOSPlatform("browser")]

BrowserApp.Define("stage-message", _ => new StageMessage());

public partial class StageMessage { }
```

`StageMessage.html`:

```html
<p>Rendered by C# in the browser.</p>
```

`wwwroot/index.html` starts the .NET runtime via the JavaScript module supplied by the OneApp browser package:

```html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>WebAssembly publishing demo</title>
</head>
<body>
  <stage-message></stage-message>
  <script type="module">
    import { boot } from './oneui-browser.js';
    await boot();
  </script>
</body>
</html>
```

The packaging command prints JSON. Its `entry` field for this build was:

```text
"entry":"index.html"
```

To preview the published files with Python 3, run this from the project folder and open `http://[::1]:8000/`. To preview the source instead, run `dotnet run` and open the HTTP **App url** it prints.

```shell
cd ../dist/StageDemo-1.0.0-web
python3 -m http.server --bind ::1 8000
```

The browser displays:

```text
Rendered by C# in the browser.
```

If `oneapp package` reports `publish_failed`, check that you’re in the WebAssembly project, that `wasm-tools` is installed, and that the project has a `wwwroot/index.html`.

## Variations

To deploy under `/demo/` instead of `/`, add this inside the `<head>` of `wwwroot/index.html`:

```html
<base href="/demo/">
```

Repackage from the project folder, upload the folder’s contents under `/demo/`, and open `/demo/` with the trailing slash.

## Related recipes

- [Use a C# WebAssembly component as a custom element](https://recursiveai.org/oneapp/cookbook/export-csharp-component-as-custom-element/)

## The short answer

Run `oneapp package . --format web --output ../dist` in your OneApp WebAssembly project. The tool publishes in Release mode by default and copies the site into a folder named for the assembly and version. Deploy that folder’s **contents**, not the C# project or the whole `dist` directory. Put `index.html`, `oneui-browser.js`, and `_framework/` at the same level, and configure the host to send `Content-Type: application/wasm` for WebAssembly files.

## Can you host a WebAssembly app without a .NET server?

Yes. The static server returns files over HTTP. In the browser, `index.html` imports `oneui-browser.js`, and `boot()` loads `_framework/dotnet.js`. The runtime runs `Main`, which registers the custom element. When OneApp creates the component, the JavaScript bridge applies its changes to the page. The server doesn’t execute `Program.cs` or need .NET installed. Don’t open the published `index.html` as a local file; preview it over HTTP so the module and runtime assets load the way they will on your host.

Set the output outside the project, as in the recipe. The example uses OneUI’s default template discovery, which looks for HTML under the project except in directories such as `wwwroot`, `bin`, and `obj`. A `dist/` folder inside the project can make the next build pick up the published `index.html` as a component template.

## What MIME type should a static host use for `.wasm`?

Use `application/wasm`, which is required for [streaming WebAssembly compilation](https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/JavaScript_interface/instantiateStreaming_static). In the browser’s Network tab, select the runtime’s `.wasm` request and check that it returns the file, not a 404 or an HTML fallback. A `200` response with `text/html` usually means the host sent a web page in place of the binary. Check the path and then the response’s `Content-Type`. The [OneApp packaging docs](https://recursiveai.org/oneapp/docs/packaging/#web-a-folder-for-any-static-host) also list the types for JavaScript, JSON, and data files.

The build includes plain files and compressed `.br` and `.gz` copies. A host that only serves plain files works. If you configure the host to send a compressed copy when the browser accepts it, keep the original content type and set `Content-Encoding: br` or `gzip`. The example turns off runtime filename fingerprinting to keep the boot module’s file name fixed, so don’t apply a year-long `immutable` cache rule to its `_framework/` files: a new release can change the bytes at the same URL.

## Can you deploy a WebAssembly app under a subdirectory?

Yes. Set the base URL before the boot script, as in the `/demo/` variation, and preserve the relative layout when you upload. For this example, a browser visiting `/demo/` must be able to get `/demo/oneui-browser.js` and `/demo/_framework/dotnet.js`. If the first loads but the second returns 404, check whether the host drops paths beginning with `_`.
For example, GitHub Pages’ default Jekyll build skips `_framework/`.
To publish these files from a branch, put an empty [`.nojekyll` file](https://docs.github.com/en/pages/getting-started-with-github-pages/creating-a-github-pages-site) at the root of the publishing source.
On another host, either configure it to serve `_framework/` or use the [documented `boot()` runtime URL override](https://recursiveai.org/oneapp/docs/browser/#serving-the-published-folder) with a directory name the host serves.
