dotnet / dotnet-wasi-sdk

An SDK for building .NET projects as standalone WASI-compliant modules
MIT License
276 stars 12 forks source link

Experimental WASI SDK for .NET Core

Wasi.Sdk is an experimental package that can build .NET Core projects (including whole ASP.NET Core applications) into standalone WASI-compliant .wasm files. These can then be run in standard WASI environments or custom WASI-like hosts.

How to use: Console applications

dotnet new console -o MyFirstWasiApp
cd MyFirstWasiApp
dotnet add package Wasi.Sdk --prerelease
dotnet build

You'll see from the build output that this produces bin/Debug/net7.0/MyFirstWasiApp.wasm.

To run it,

Alternatively you can invoke runners like wasmtime or wasmer manually on the command line. For example,

Other WASI hosts work similarly.

How to use: ASP.NET Core applications

dotnet new web -o MyWebApp
cd MyWebApp
dotnet add package Wasi.Sdk --prerelease
dotnet add package Wasi.AspNetCore.Server.Native --prerelease

Then:

That's it! You can now run it via dotnet run (or in VS, use Ctrl+F5)

Optionally, to add support for bundling wwwroot files into the .wasm file and serving them:

What's in this repo

... and more

Building this repo from source

First, build the runtime. This can take quite a long time.

Now you can build the packages and samples in this repo:

Contributing

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information, see the .NET Foundation Code of Conduct.