Compile and run C# programs using WASM:
const module = await WasmSharpModule.initializeAsync()
const compilation = await module.createCompilationAsync(`
using System;
Console.WriteLine("Hello World!");
`)
const result = await compilation.run();
console.log(result.success); // true
console.log(result.stdOut); // Hello World!
const module = await WasmSharpModule.initializeAsync()
const compilation = await module.createCompilationAsync(`
using System;
WriteLine("Hello World!");
`)
const result = await compilation.run();
console.log(result.success); // false
console.log(result.diagnostics);
/*
[
{
"id": "CS0103",
"message": "The name 'WriteLine' does not exist in the current context",
"location": {
"start": 3,
"end": 12,
"length": 9,
"isEmpty": false
},
"severity": "Error"
}
]
*/
Web worker mode (the default mode) requires a HTTPS URL (or localhost in some browsers). Disable web worker mode using disableWebWorker: true
:
const module = await WasmSharpModule.initializeAsync({
disableWebWorker: true
})
This project uses pnpm. Installation instructions for pnpm can be found here.
- pnpm
- .NET 8.0 SDK or greater
- Ensure the
wasm-tools
workload is installed. It can be installed using
dotnet workload install wasm-tools
- Ensure the
pnpm i
pnpm init-playground-deps
pnpm start
pnpm build:core
pnpm test
pnpm --filter playground build
Build is created in the playground/dist/ folder.
pnpm serve
Building and serving the playground has a shortcut command:
pnpm build-serve
Building @wasmsharp/core, building the playground, and then previewing it has a shortcut command:
pnpm all