Set Up .NET Development Environment
To integrate MATLAB® code into .NET applications, start by authoring your MATLAB code using the MATLAB desktop. Then, utilize MATLAB Compiler SDK™ to generate .NET components. Finally, complete the integration process in your preferred C# development environment, including a text editor along with the .NET SDK Command Line API or Microsoft® Visual Studio® on Windows® and macOS.
The files you need to include in your setup depend on whether you're using the modern MATLAB Data API for .NET or the legacy MWArray API.
.NET Command Line API
Use the .NET SDK command-line interface (CLI) along with a code editor to integrate
MATLAB code within .NET applications. You must use .NET 6.0 or higher. You can
verify whether .NET 6.0 is installed by typing dotnet --info at a
system command prompt. For details, see .NET CLI
Overview.
MATLAB Data API for .NET
Add the following assembly dependencies to your project:
MathWorks.MATLAB.Runtime.dllMathWorks.MATLAB.Types.dll
Windows Paths to MathWorks Assemblies
Linux and macOS Paths to MathWorks Assemblies
Edit the project file (.csproj) and add the above references
using the <ItemGroup> tag. For
example:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Reference Include="MathWorks.MATLAB.Runtime">
<HintPath>C:\Program Files\MATLAB\MATLAB Runtime\R2026a\extern\dotnet\netstandard2.0\MathWorks.MATLAB.Runtime.dll</HintPath>
</Reference>
<Reference Include="MathWorks.MATLAB.Types">
<HintPath>C:\Program Files\MATLAB\MATLAB Runtime\R2026a\extern\dotnet\netstandard2.0\MathWorks.MATLAB.Types.dll</HintPath>
</Reference>
</ItemGroup>
</Project>
MWArray API
Add the following assembly dependency to your project:
MWArray.dll
Microsoft Visual Studio
If you use Visual Studio for integration, first verify that you have installed Microsoft Visual Studio 2022 (v17.0 or higher).
MATLAB Data API for .NET
Add the MathWorks® assemblies listed above from the Solution Explorer:
In Solution Explorer, right-click the Dependencies node and choose Add Project Reference.
Browse for the MathWorks assembly dependencies mentioned above in the Reference Manager and add them.
Set PATH Environment Variable to Configure Native Library Access for Runtime Libraries
Before executing your C# application in Visual Studio, ensure that your PATH environment variable is
correctly set to reference your MATLAB or MATLAB Runtime installation. Here's how you can set the PATH
environment variable within Visual Studio:
In Visual Studio, right-click your project in Solution Explorer, then click Properties.
Navigate to Debug > General, and select Open debug launch profiles UI.
In the Launch Profiles window, under Environment variables, set your
PATH:For MATLAB:
PATH=C:\Program Files\MATLAB\R2026a\runtime\win64For MATLAB Runtime:
PATH=C:\Program Files\MATLAB\MATLAB Runtime\R2026a\runtime\win64
MWArray API
Add the MWArray.dll assembly as a reference from one of the
following locations.
Configure Native Library Access for Runtime Libraries
Note
If you are using Microsoft
Visual Studio, see the section above on how to set the PATH
environment variable to configure native library access for runtime libraries.
To run .NET applications that use components generated by MATLAB
Compiler SDK, the .NET runtime must be able to locate the native libraries included in
MATLAB or MATLAB Runtime. These are platform-specific files (.dll,
.so, or .dylib) are required for loading and
executing packaged MATLAB code.
To make these libraries available, update the operating system’s native library search path by modifying the appropriate environment variable.
| Platform | Environment Variable |
|---|---|
| Windows | PATH |
| Linux® | LD_LIBRARY_PATH |
| macOS | DYLD_LIBRARY_PATH |
For details, see Set MATLAB Library Paths for Testing Deployed Applications.
Caution
When testing applications on a machine with a full MATLAB installation, you can set up native library access using the MATLAB installation.
In a deployment scenario where MATLAB Runtime is used, you must explicitly specify the location of the native libraries within an installation of MATLAB Runtime. This distinction ensures that deployed applications run independently of a full MATLAB installation.
See Also
Topics
- MATLAB Compiler SDK .NET Target Requirements
- Deploy MATLAB Function to .NET Application Using MATLAB Data API for .NET