Using MeshLib with C#
This instruction will guide you through integrating MeshLib into your C# project using NuGet or the .NET Command-Line Interface.
- Note
- MeshLib C# bindings are fully generated from the C++ codebase and expose the complete public API, with the exception of the
MR.Viewer module. The C# API is fully compatible with Unity.
-
As of January 2026, the C# bindings are production-ready. The full, stable C# API reference and comprehensive code samples are available and maintained. C# support is provided consistently across all supported platforms (Windows x64, Linux x64/Arm, MacOS x64/Arm), ensuring feature parity with the native C++ API.
Prerequisites
Before installing MeshLib, ensure you have the following tools installed:
.NET SDK
- Install the latest version of the .NET SDK from the .NET website. MeshLib is compatible with .NET Framework 4.7 and higher, as well as .NET 5.0, 6.0, 7.0, 8.0, and additional versions outlined below.
- Verify your installation by running:
Visual Studio
For a more integrated development experience, you can use Visual Studio 2019 or later. Make sure to install the **.NET desktop development** workload.
Installation via NuGet
Depending on your development environment and workflow preferences, you can choose from the following installation methods
Using Visual Studio on Windows
To install MeshLib via Visual Studio, follow these steps:
- Open Your Project in Visual Studio:
- If you don’t have a project yet, create a new C# Console App (.NET Core) or another suitable project type.
- Open the NuGet Package Manager:
- Right-click on your project in the Solution Explorer.
- Select "Manage NuGet Packages."
- Search for MeshLib:
- In the NuGet Package Manager, switch to the "Browse" tab.
- Enter "MeshLib" in the search box.
- Install the Package:
- Select the MeshLib package from the search results.
- Click "Install" and follow any prompts to complete the installation.
- Start Using MeshLib:
- You should now have access to the static class
MR and its members.
Installation from a Downloaded NuGet Package
If you prefer to download the MeshLib package directly from the NuGet website, follow these steps:
- Download the MeshLib Package:
- Create a Local Directory for NuGet Packages:
- Choose or create a directory on your system where you will store the
.nupkg file. For example: mkdir ~/LocalNuGetPackages
- Move the downloaded
MeshLib.nupkg file to this directory.
- Install the MeshLib Package Locally:
- Use the command below to install the package:
dotnet add package MeshLib --source /path/to/LocalNuGetPackages
- Alternative: Configure Local Source Globally:
- Add the local directory as a source using:
dotnet nuget add source \path\to\LocalNuGetPackages --name LocalPackages
- After this, you can install the package normally without specifying
-source.
- Build and Run Your Project:
Installation via .NET Command-Line Interface
To install MeshLib via the .NET CLI, follow these steps:
- Open a Terminal or Command Prompt:
- On Windows, use Command Prompt, PowerShell, or the Windows Terminal.
- Create a New Project Directory:
Run the following commands to create a new directory for your project and navigate into it: mkdir TestProject
cd TestProject
- Create a New .NET Console Project:
Inside the new directory, initialize a .NET console project by running:
- Install the MeshLib Package:
Use the following command to add MeshLib to your project: dotnet add package MeshLib
- Build and Run Your Project:
After installing MeshLib, you can build and run your project using:
By following these steps, you can integrate MeshLib into your project, giving you more control over the setup process.
Try MeshLib with C# Examples
MeshLib provides a collection of C# code samples to help you get started quickly with common mesh processing tasks. These are concise, self-contained examples — perfect for exploring how to use MeshLib’s API in your own projects:
- Load and Save Meshes Demonstrates how to load and export mesh files using the MeshLib API.
- Mesh Boolean Operations Shows how to perform boolean operations like union, intersection, and subtraction between meshes.
- Mesh Simplification Illustrates how to reduce mesh complexity through decimation, preserving overall shape with fewer polygons.
These samples are a great starting point for integrating MeshLib into C# or .NET-based workflow.