Matlab .NET on Linux, macOS, and Windows
Matlab external language interfaces includes .NET on Windows, Linux, and macOS. This allows efficiently calling .NET assemblies and using .NET libraries directly from Matlab.
The Matlab function
dotnetenv
is used to set up and check the active .NET environment in Matlab.
Environment variable DOTNET_ROOT
is vital for Matlab to detect the .NET installation, particularly on Linux and macOS.
If Matlab is having issues detecting the .NET installation NET.isNETSupported
is false, determine the value for DOTNET_ROOT
from system Terminal:
dotnet --info
Set the DOTNET_ROOT
environment variable in Matlab by adding to Matlab startup.m so that future Matlab sessions have the correct DOTNET_ROOT
set.
edit(fullfile(userpath,'startup.m'))
Then add the following line to startup.m
:
setenv("DOTNET_ROOT", <DOTNET_ROOT path from dotnet --info>)
Restart Matlab. Do the following one-time command to finish settting up .NET in Matlab:
dotnetenv("core", Version=8)
The Version number must match the major version of .NET in DOTNET_ROOT. On future Matlab sessions, dotnetenv() will be empty until the first .NET command is run, for example
NET.isNETSupported
then (optionally) running dotnetenv()
shows the current .NET environment.