@wasmsharp/core
v0.10.2
Published
<h2 align='center'><samp>WasmSharp</samp></h2>
Maintainers
Readme
Live demo
https://wasmsharp.pages.dev/
Install
npm i @wasmsharp/core
# or
yarn add @wasmsharp/core
# or
pnpm add @wasmsharp/coreGetting started
Compile and run a basic C# program:
// downloads and initializes the .NET runtime, loads the Roslyn C# compiler
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;
// intentional error - missing Console in front of "WriteLine"
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"
}
]
*/Troubleshooting
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
})Development setup
This project uses pnpm. Installation instructions for pnpm can be found here.
Prerequisites
- pnpm
- .NET 10.0 SDK or greater
- Ensure the
wasm-toolsworkload is installed. It can be installed using
dotnet workload install wasm-tools - Ensure the
Install packages
pnpm iBuild all required depedencies to run the playground
pnpm init-playground-depsRun the playground
pnpm startBuilding @wasmsharp/core
pnpm build:coreRun tests
pnpm testDeploying the Playground
Build the playground
pnpm --filter playground buildBuild is created in the playground/dist/ folder.
Serve the production build of the playground
pnpm serveBuilding and serving the playground has a shortcut command:
pnpm build-serveBuilding @wasmsharp/core, building the playground, and then previewing it has a shortcut command:
pnpm all