Prerequisite software tool
-
Visual Studio 2019 with .NET desktop development & .NET cross-platform development & Desktop development with C++ workload:
- Windows 10 SDK version 10.0.10586 or later:
Can be installed via Individual Components section of Visual Studio 2019 Installer:
or Use downloaded SDK installer. - CMake and add its executable location to PATH environment variable.
Build native RealSense library & C# wraaper
Build Windows version native RealSense library
- On Windows 10 machine that had above Prerequisite software tools installed, Clone the source from Intel RealSense SDK git repository.
-
Generate Visual Studio solution files in git repository top level directory via Developer Command Prompt/PowerShell for VS 2019:
mkdir build cd build cmake .. -DBUILD_CSHARP_BINDINGS=ON -DBUILD_SHARED_LIBS=ON Open generated build\librealsense2.sln solution file in Visual Studio 2019, if prompt the following dialog, select first option to change target to .NET framework 4.6.1:

Select the C++ project in Library/realsense2, then make sure the configuration is set to Release, and x64:

Right click and select build to start building native RealSense C++ library dll for Windows:

It will take quite a long time to build, after successfully build, there should be a
realsense2.dllfile inside the build\Release folder:

This is the native RealSense library for Windows, copy it for later usage.
Build .NET 5 C# wrapper of RealSense SDK
-
Create a text file called
Intel.RealSense.csprojinside the wrappers\csharp\Intel.RealSense folder with following content:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net5.0-windows</TargetFramework> <GenerateAssemblyInfo>false</GenerateAssemblyInfo> </PropertyGroup> </Project> Run
dotnet build -c Releasein wrappers\csharp\Intel.RealSense directory:

And you will find two filesIntel.RealSense.dll&Intel.RealSense.pdbinside the wrappers\csharp\Intel.RealSense\bin\Release\net5.0-windows directory, these two are C# wrapper library files, copy them for later usage:

.NET 5 project usage demo
Demo project is on GitHub: https://github.com/windperson/Net5RealSenseDemo
It is just a .NET 5 console project, but you have to manually modify the .csproj file content:
- Set .NET 5+ OS-specific TFMs to
net5.0-windows. - Add RuntimeIdentifier to
win10-x64 - Native RealSense library files need be copied into .NET executable file's folder by MSBuild:

Top comments (0)