Wasm/WASI for MSBuild
- MSBuild task is an unit of execution inside a build, that can be created by users of MSBuild
- experimental project exporing using Wasm/WASI to create MSBuild tasks
- Wasm/WASI supports multiple languages extending the notion of a MSBuild Task from a C# class to a Wasm module
- Rust example tasks [examples/]
- The tasks run in a Wasm/WASI runtime - Wasmtime which sandboxes the execution from the rest of the system and files/directories a task allowed to touch have to be specified.
see spec for details
Create a MSBuild task using Wasm/WASI toolchain.
- install wasi-sdk, cargo, build the .dll for MSBuildWasm (e.g. by
dotnet publish src
) - copy rust_template from the examples folder and add your behavior to the
lib.rs
file, take care to specify the input/output parameters - compile with
cargo build --release --target wasm32-wasi
- in your project's
project.csproj
that you want to build with MSBuild include the task
<UsingTask TaskName="MyWasmTask" AssemblyFile="MSBuildWasm.dll" TaskFactory="WasmTaskFactory">
<Task>your_module.wasm</Task>
</UsingTask>
- use the task in a target
<Target Name="MyWasmTarget" AfterTargets="Build">
<MyWasmTask Param="StringParam" Param2="true">
<Output TaskParameter="Result" PropertyName="TaskResult"/>
</MyWasmTask>
</Target>
dotnet build
Inputs and outputs from a tasks can be bools, strings and "ITaskItem" which is basically a file path.