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.
Ruststudio packs a Rust library as a NuGet package with a generated C# wrapper, so a .NET project can call it after dotnet add package, and it restores NuGet packages with native libraries into Rust projects.
Updated · describes Ruststudio 0.1.7

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.
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.
Try it
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 Ruststudio 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”.
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. Ruststudio 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 Ruststudio. Managed .NET libraries are not hosted inside Rust programs.
Something else? Ask in the community forum or send feedback.
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 Ruststudio.
Yes. Ruststudio is free for personal and commercial use, with no licence key and nothing to pay. Use it for 7 days straight away; after that you sign up for a free account with your e-mail address. It is closed-source freeware.
Ruststudio is a product of FOWLGUARD, Inc., the company behind Fowlguard Secure and Fowlguard Productivity. It is one of its free tools; see fowlguard.com.
Windows 10 and 11 (64-bit), macOS 11 or later (Apple silicon and Intel) and Linux (x86-64, X11 or Wayland). You can build for the desktop, the web and Android from it. Native iOS support is in development and will need a Mac with Xcode.