Skip to content

Commit 9c94446

Browse files
authored
Add C# docs (#1105)
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
1 parent f3a3ac0 commit 9c94446

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,56 @@ Like with Rust, you can then inspect the output binary:
309309
wasm-tools component wit ./my-component.wasm
310310
```
311311

312+
### Guest C#
313+
314+
To generate the bindings:
315+
316+
```
317+
wit-bindgen c-sharp -w command -r native-aot --generate-stub wit/
318+
```
319+
320+
Now you create a c# project file:
321+
322+
```
323+
dotnet new console -o MyApp
324+
cd MyApp
325+
dotnet new nugetconfig
326+
```
327+
328+
In the `nuget.config` after `<clear />`make sure you have:
329+
330+
```
331+
<add key="dotnet-experimental" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json" />
332+
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
333+
```
334+
335+
In the MyApp.csproj add the following to the property group:
336+
337+
```
338+
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
339+
<UseAppHost>false</UseAppHost>
340+
<PublishTrimmed>true</PublishTrimmed>
341+
<InvariantGlobalization>true</InvariantGlobalization>
342+
<SelfContained>true</SelfContained>
343+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
344+
<WASI_SDK_PATH>path/to/wasi-sdk</WASI_SDK_PATH>
345+
```
346+
347+
Add the native-aot compiler (substitute `win-x64` for `linux-x64` on Linux):
348+
349+
```
350+
dotnet add package Microsoft.DotNet.ILCompiler.LLVM --prerelease
351+
dotnet add package runtime.win-x64.Microsoft.DotNet.ILCompiler.LLVM --prerelease
352+
```
353+
354+
Now you can build with:
355+
356+
```
357+
dotnet publish
358+
```
359+
360+
Checkout out [componentize-dotnet](https://github.com/bytecodealliance/componentize-dotnet) for a simplified experience.
361+
312362
### Guest: Java
313363

314364
Java bytecode can be compiled to WebAssembly using

0 commit comments

Comments
 (0)