C#
First install the .NET7 SDK package from https://dotnet.microsoft.com/en-us/download/dotnet/7.0 (opens in a new tab)
You also have to install everything as described in Common tooling.
Then use the dotnet CLI tool to create a new package:
dotnet new console -o csharp-1
dotnet add package Wasi.Sdk --prereleaseThe easiest way to get started once the tooling is installed is to use the golem new command as described in the Quickstart.
An example program that takes some use of WASI could be the following Program.cs:
using System.Collections;
 
var rand = new Random();
var now = DateTime.Now;
 
Console.WriteLine("Hello, World!");
Console.WriteLine(rand.NextInt64(0, 1000));
Console.WriteLine(now.Year);
foreach (DictionaryEntry kv in System.Environment.GetEnvironmentVariables()) {
    Console.WriteLine(kv.Key + ": " + kv.Value);
}Build the program into WASM using
dotnet buildThe resulting main.wasm is a WASM module not a component, so we have to use the tier 2 WASI adapter and wasm-tools to convert it to a WASM component:
wasm-tools component new main.wasm -o component.wasm --adapt tier2/wasi_snapshot_preview1.wasmThe wasi_snapshot_preview1.wasm describes the mapping from WASI Preview1 to Preview2. You must use the version of this file packaged together with golem-cli.
The resulting component.wasm is ready to be used with Golem.