Pack
Rust library to NuGet
Reads your extern "C" functions, builds in release, generates a C# class and writes a .nupkg with the native library for each platform.
Pack a Rust library as a NuGet package that C# developers can add with one command, and restore NuGet native libraries into your Rust solution.

Turn extern "C" functions into a C# wrapper and a package, and use native NuGet packages in Rust.
src/lib.rs (edit me)
Native.cs (generated: 4 functions)
// <auto-generated> by Rust Studio from the extern "C" functions in lib.rs
using System;
using System.Runtime.InteropServices;
namespace MathLib;
public static class Native
{
private const string Lib = "mathlib";
[DllImport(Lib, EntryPoint = "add", CallingConvention = CallingConvention.Cdecl)]
private static extern int add_raw(int a, int b);
public static int Add(int a, int b) => add_raw(a, b);
[DllImport(Lib, EntryPoint = "scale", CallingConvention = CallingConvention.Cdecl)]
private static extern double scale_raw(double x, double factor);
public static double Scale(double x, double factor) => scale_raw(x, factor);
// string arguments are marshalled as UTF-8
[DllImport(Lib, EntryPoint = "greet", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
private static extern IntPtr greet_raw([MarshalAs(UnmanagedType.LPUTF8Str)] string name);
public static string Greet(string name)
{
var p = greet_raw(name);
try { return Marshal.PtrToStringUTF8(p)!; } finally { FreeString(p); }
}
[DllImport(Lib, EntryPoint = "free_string", CallingConvention = CallingConvention.Cdecl)]
private static extern void free_string_raw(IntPtr s);
private static void FreeString(IntPtr p) => free_string_raw(p);
}Package contents
MathLib.0.1.0.nupkg ├─ MathLib.nuspec ├─ contentFiles/cs/any/Native.cs (the generated wrapper, compiled into the consumer) ├─ runtimes/win-x64/native/mathlib.dll └─ [Content_Types].xml
In a C# project
dotnet add package MathLib --version 0.1.0 --source ./nupkg Console.WriteLine(Native.Add(2, 3)); // 5
Try it: edit the Rust functions and watch the C# wrapper follow, add a platform, then try “Use NuGet in Rust”.
Pack
Reads your extern "C" functions, builds in release, generates a C# class and writes a .nupkg with the native library for each platform.
Wrapper
Integers, floats, bool, strings and pointers are mapped for you. Returned strings are freed through your library's free function.
Use
Search nuget.org, restore packages with native libraries into the solution, and add them to build.rs in one click.
Template
A cdylib starter with an add function, a string function and a free function, ready to pack.
Rust is a good place for the code that must be fast, safe and portable, and .NET is a good place for the application around it. Packing a Rust library as a NuGet package lets a C# project call it like any other library: dotnet add package, then Native.Add(2, 3).
The package carries the generated wrapper as source that compiles into the consuming project, and the native library under runtimes/<platform>/native, which is where .NET looks for it. We verified it end to end with a real C# program restoring the package and calling the Rust code.
Many native SDKs ship on NuGet. Rust Studio restores them into the solution, gives your builds a NUGET_<ID>_DIR variable, and Use in project writes a block into build.rs that adds the package's native folder to the linker path and copies its libraries next to your program.
This covers packages that carry native libraries, including Rust libraries packed by Rust Studio. Managed .NET libraries are not hosted inside Rust programs.
No. The package contains the compiled native library. The .NET project only needs the package.
The platform you build on, plus any target you have built under target/<triple>/release before packing.
Native packages, yes. Managed .NET libraries are not hosted inside Rust programs by Rust Studio.
Yes. Rust Studio is free for personal and commercial use, with no account, trial or licence key. It is closed-source freeware.
Windows 10 and 11 (64-bit). You can build for Windows, the web and Android from it. iOS builds need a Mac with Xcode.
Rust Studio is a free, native Rust IDE for Windows: rust-analyzer, solutions with many projects, full-stack web templ…
Build Windows desktop apps in Rust with Tauri, Slint or egui. Rust Studio gives you project templates, solutions, a o…
Build full-stack Rust web apps in Rust Studio: an axum backend with a React, Vue, Svelte or Angular front end, a dev…
Download Rust Studio, the free Rust IDE for Windows 10 and 11. Per-user install, no administrator rights, no account,…