Community.MauiRust.Generators 1.0.0-pre11

This is a prerelease version of Community.MauiRust.Generators.
dotnet add package Community.MauiRust.Generators --version 1.0.0-pre11
                    
NuGet\Install-Package Community.MauiRust.Generators -Version 1.0.0-pre11
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Community.MauiRust.Generators" Version="1.0.0-pre11">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Community.MauiRust.Generators" Version="1.0.0-pre11" />
                    
Directory.Packages.props
<PackageReference Include="Community.MauiRust.Generators">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Community.MauiRust.Generators --version 1.0.0-pre11
                    
#r "nuget: Community.MauiRust.Generators, 1.0.0-pre11"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Community.MauiRust.Generators@1.0.0-pre11
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Community.MauiRust.Generators&version=1.0.0-pre11&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Community.MauiRust.Generators&version=1.0.0-pre11&prerelease
                    
Install as a Cake Tool

Community.MauiRust.Generators

Build-time package for .NET MAUI + Rust projects.

Reads your rust/lib.rs, finds every #[no_mangle] pub extern "C" fn, and generates matching [LibraryImport] P/Invoke bindings into Rust.Generated.cs — automatically, on every build.

How it works

Add a Rust export:

#[no_mangle]
pub extern "C" fn compute(value: f32) -> f32 {
    value * 2.0
}

The generator emits:

// Rust.Generated.cs — do not edit
[LibraryImport(Lib, EntryPoint = "compute")]
[UnmanagedCallConv(CallConvs = new[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
public static partial float Compute(float value);

Call it from C#:

var result = Rust.Compute(3.14f);

Override a binding

Declare the same EntryPoint in your Rust.cs — the generator skips it:

// Rust.cs — your file, generator leaves this alone
[LibraryImport(Lib, EntryPoint = "compute")]
public static partial float Compute(float value);

Unknown types

If the generator cannot map a Rust type to C#, it emits a TODO comment instead of broken code:

// TODO: bind 'complex_func' — unrecognized type(s), declare manually in Rust.cs

Setup

Installed via Community.MauiRust.Templates

Zero config. The template package includes the generator and emits a fixed Community.MauiRust.Generators package reference in the scaffolded app.

Install into an existing app from NuGet

You can also add the package to an existing MAUI project with the CLI:

dotnet add package Community.MauiRust.Generators

After that, make sure your project follows the expected layout or set the relevant MSBuild overrides shown below.

Manual install

<PackageReference Include="Community.MauiRust.Generators" Version="1.0.0-pre11">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

The package reads rust/Cargo.toml to infer the native library name and writes the generated Lib constant for you when Rust.cs does not already define one.

The package also wires the build-time generation logic from the repo-level build/Community.MauiRust.Generators.targets file. RustCrateDir defaults to the template layout, but you can override it.

Optional MSBuild properties

The package works with no required properties in template-generated projects, but it supports these optional overrides in your app .csproj:

Property Default value Purpose
RustCrateDir ../../rust from the app project directory Path to the Rust crate root
RustLibName Auto-read from Cargo.toml [package].name and normalized for Rust Native library name
RustProfile release Cargo profile to build with
RustCargoToolchainArgs Empty Extra toolchain selector arguments such as +nightly
RustGeneratorSrcDir $(RustCrateDir) Override path for lib.rs when it is not under the crate root
RustGeneratedFile $(MSBuildProjectDirectory)\Rust.Generated.cs Override output path for Rust.Generated.cs

For example, with a custom layout:

<PropertyGroup>
  <RustCrateDir>..\..\native\mycrate</RustCrateDir>
  <RustGeneratorSrcDir>..\..\rust</RustGeneratorSrcDir>
  <RustLibName>your_crate_name</RustLibName>
  <RustProfile>release</RustProfile>
  <RustGeneratedFile>Generated\RustBindings.g.cs</RustGeneratedFile>
</PropertyGroup>

Supported type mappings

Rust C#
i32 / c_int int
u32 / c_uint uint
f32 / c_float float
f64 / c_double double
i64 / u64 long / ulong
isize / usize nint / nuint
*mut c_void / *const c_void IntPtr
*mut u8 / *const u8 IntPtr

Everything else → TODO comment.

Repo layout

Inside the combined Community.MauiRust repo the package lives here:

src/Community.MauiRust.Generators/
build/Community.MauiRust.Generators.targets
build/Community.MauiRust.Generators.props

The template package under src/Community.MauiRust.Templates/ consumes this package.

Both packages are released together from the combined repo via .github/workflows/nuget-release.yml.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-pre11 91 4/26/2026