Building Qt Bridge for C# from source
Building the NuGet Package and Test Application (Windows, .NET 8)
This guide documents the steps used to:
- Build a minimal Qt 6 from source (subset of modules)
- Build the Qt Bridge for C# (adapter, generator, rules)
- Build/Run the test application against the local package
Prerequisites
- Visual Studio 2022 (Desktop development with C++) with the x64 Native Tools Command Prompt (required because Qt Bridge generates C++ code)
- .NET SDK 8+ (
dotnet --version) - Git
- CMake & Ninja (installed with VS; available in the native tools prompt)
- Python & Perl (required only if you build Qt from source) - see Qt's system requirements
- Sufficient disk space (Qt build can require tens of GB)
Note: System requirements reference: https://wiki.qt.io/Building_Qt_6_from_Git#System_Requirements
Using an existing Qt installation
If you already have a Qt 6 installation that includes qtbase, qtsvg, qtshadertools, qtdeclarative, qtquick3d, qtquick3dphysics, and qtquicktimeline, you can skip building Qt from source. In the x64 Native Tools Command Prompt for VS 2022, set QtInstallRoot to the Qt installation prefix (the folder that contains bin, lib, and include), then continue with Build the Qt Bridge for C#.
set QtInstallRoot=D:\Qt\6.11.0\msvc2022_64Build Qt 6 (subset) from source
Note: The paths below use D:\work for demonstration. Adjust as needed. All commands are meant to run from the x64 Native Tools Command Prompt for VS 2022.
Open x64 Native Tools Command Prompt for VS 2022 and run:
# Choose a working directory
pushd D:\work
# Create source/build/install folders
mkdir qt6-source
mkdir qt6-build
mkdir qt6-install
# Clone Qt meta-repo (Qt 6 uses the qt5 meta-repo name)
git clone https://code.qt.io/qt/qt5.git qt6-source
# Initialize only the modules we need
cd qt6-source
init-repository --module-subset=qtbase,qtsvg,qtshadertools,qtdeclarative,qtquick3d,qtquick3dphysics,qtquicktimeline
# Configure out-of-source build
cd ..\qt6-build
..\qt6-source\configure -prefix ..\qt6-install -release -opensource -confirm-license -submodules qtbase,qtsvg,qtshadertools,qtdeclarative,qtquick3d,qtquick3dphysics,qtquicktimeline -- -DQT_BUILD_TESTS=OFF -DQT_BUILD_EXAMPLES=OFF
# Build and install
cmake --build .
cmake --install .Notes
- You can add
-DCMAKE_BUILD_PARALLEL_LEVEL=Nto speed up builds (or usecmake --build . --parallel). - If you run into generator issues, you can specify
-G "Ninja"and install Ninja. - The above turns off Qt tests/examples to keep the build lean.
Set Qt environment for the session
Use the same native tools prompt you used to build Qt:
set QtInstallRoot=D:\work\qt6-installIf you used an existing Qt installation, set QtInstallRoot to that path instead.
Build the Qt Bridge for C#
From the same prompt:
# Go to your Qt Bridge for C# source checkout
pushd D:\work\qtbridge-csharp
# Restore and build (Release)
dotnet build -c ReleaseBuild the test app as a smoke test:
# Build the test app (adjust the path if different)
dotnet build -c Release examples\Primes\Primes.csprojTest the package locally with the sample app
From the same prompt:
# Build & run the sample app
dotnet run --project examples\Primes\Primes.csproj -c ReleaseTroubleshooting
- MSVC/CMake not detected: Make sure you're using the x64 Native Tools prompt.
- Missing Python/Perl: Install them and ensure they're on
PATHbefore runninginit-repository/configure. - Long paths or spaces: Prefer short, space-free paths like
D:\work. - Rebuild from scratch: Delete the entire content of
qt6-buildandqt6-installdirectory and configure again.
What gets packaged
The NuGet contains:
- .NET adapter (host Qt/QML engine from C#)
- Generator (discovers your types and emits interop glue)
- Filtering rules (Include/Ignore/Exclude attributes)
- C++ include headers for the native bridge
- A minimal open-source Qt Quick runtime subset sufficient to run QML
All parts are versioned together to ensure compatibility.
Clean up
To revert environment changes, close the prompt or manually unset variables:
set QtInstallRoot=After completing the steps above, you'll have:
- A locally built Qt install at
%QtInstallRoot% - A Release build of Qt Bridge for C#
- A NuGet package in
nuget\local - A test application built against that package
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.