Prerequisites
- .NET Framework 4.5+ or .NET Core 2.0+ or .NET 5+
- Visual Studio (recommended) or any .NET-compatible IDE
- NuGet package manager
Installation Options
Option 1: NuGet Package (Recommended)
The easiest way to use Z3 in .NET projects is via the official NuGet package.- Package Manager Console
- .NET CLI
- PackageReference
The NuGet package includes native binaries for Windows, Linux, and macOS, so no additional configuration is needed.
Option 2: Pre-built Binaries
Download from the GitHub Releases page.Download Z3
Download the appropriate package:
- Windows:
z3-x.x.x-x64-win.zip - Linux:
z3-x.x.x-x64-glibc-x.x.zip - macOS:
z3-x.x.x-x64-osx-x.x.zip
Locate .NET Files
The
bin directory contains:Microsoft.Z3.dll- .NET assemblylibz3.dll/libz3.so/libz3.dylib- Native library
Option 3: Build from Source
Build Z3 with .NET bindings enabled:build directory.
Visual Studio Setup
New Project with NuGet
Install NuGet Package
Right-click project → Manage NuGet Packages → Search for “Microsoft.Z3” → Install.
Manual Reference (Without NuGet)
.NET Core / .NET 5+ CLI
Create New Project
Project File Example
MyZ3App.csproj
Verify Installation
Create a test file:Program.cs
F# Setup
Z3 works seamlessly with F#:Program.fs
Platform-Specific Notes
Windows
- Native library:
libz3.dll - The NuGet package automatically handles native dependencies
- For manual installation, ensure
libz3.dllis in the same directory as your executable or in PATH
Linux
- Native library:
libz3.so - May need to install dependencies:
sudo apt-get install libgomp1(Ubuntu/Debian) - Set
LD_LIBRARY_PATHif needed:export LD_LIBRARY_PATH=/path/to/z3/lib:$LD_LIBRARY_PATH
macOS
- Native library:
libz3.dylib - Set
DYLD_LIBRARY_PATHif needed:export DYLD_LIBRARY_PATH=/path/to/z3/lib:$DYLD_LIBRARY_PATH
Troubleshooting
FileNotFoundException: Microsoft.Z3.dll
Problem: Cannot find the managed assembly. Solution:- Reinstall the NuGet package
- If using manual reference, verify the path to
Microsoft.Z3.dll - Check that the assembly is being copied to the output directory
DllNotFoundException: libz3
Problem: Cannot load the native library. Solution:- Windows: Ensure
libz3.dllis in the same folder as your exe or in PATH - Linux: Install required dependencies, set
LD_LIBRARY_PATH - macOS: Set
DYLD_LIBRARY_PATH - If using NuGet, try cleaning and rebuilding:
dotnet clean && dotnet build
BadImageFormatException
Problem: Architecture mismatch (32-bit vs 64-bit). Solution:- Ensure your application target matches the Z3 binary architecture
- Most Z3 distributions are 64-bit; set your project to x64:
- Project Properties → Build → Platform target → x64
- Or in .csproj:
<PlatformTarget>x64</PlatformTarget>
TypeLoadException
Problem: Version mismatch between managed and native libraries. Solution:- Ensure
Microsoft.Z3.dllandlibz3.*are from the same Z3 version - Reinstall the NuGet package
NuGet Package Details
The official NuGet package:- Package ID:
Microsoft.Z3 - Homepage: https://www.nuget.org/packages/Microsoft.Z3/
- Repository: https://github.com/Z3Prover/z3
- License: MIT
Microsoft.Z3.dll- Managed .NET assembly- Native libraries for Windows (x64, x86, ARM64)
- Native libraries for Linux (x64, ARM64)
- Native libraries for macOS (x64, ARM64)
Multi-Targeting
For libraries that target multiple frameworks:Next Steps
Getting Started
Learn the basics of the Z3 .NET API
API Reference
Explore the complete .NET API documentation
NuGet Package
View on NuGet.org
