Main Content

.NET Development Environment

To deploy MATLAB® code within .NET applications you need to setup your development environment.

  • Use the MATLAB desktop to author MATLAB code and MATLAB Compiler SDK™ to generate .NET components from MATLAB code.

  • Use the .NET 5.0 SDK command-line interface (CLI) along with a code editor or Microsoft® Visual Studio® to integrate MATLAB code within .NET applications. Verify that you have .NET 5.0 SDK or Microsoft Visual Studio 2019 or higher installed. If you have version 16.8.0 of Visual Studio 2019 installed, then you do not need to install .NET 5.0 or higher separately. You can verify whether .NET 5.0 is installed by typing dotnet --info at a system command prompt. For details, see .NET CLI Overview.

  • Add the following assembly dependencies to your project:

    • MathWorks.MATLAB.Runtime.dll

    • MathWorks.MATLAB.Types.dll

    If MATLAB is installed on your system

    • matlabroot\extern\dotnet\netstandard2.0\MathWorks.MATLAB.Runtime.dll

    • matlabroot\extern\dotnet\netstandard2.0\MathWorks.MATLAB.Types.dll

    If MATLAB Runtime is installed on your system

    • <MATLAB_RUNTIME_INSTALL_DIR>\extern\dotnet\netstandard2.0\MathWorks.MATLAB.Runtime.dll

    • <MATLAB_RUNTIME_INSTALL_DIR>\extern\dotnet\netstandard2.0\MathWorks.MATLAB.Types.dll

    You can test your .NET application against the installed version of MATLAB that was used to generate the .NET artifacts or against an installation of MATLAB Runtime. However, during deployment you must use MATLAB Runtime.

    If you are using the .NET 5.0 SDK along with a code editor for development, 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\R2022b\extern\dotnet\netstandard2.0\MathWorks.MATLAB.Runtime.dll</HintPath>
        </Reference>
        <Reference Include="MathWorks.MATLAB.Types">
          <HintPath>C:\Program Files\MATLAB\MATLAB Runtime\R2022b\extern\dotnet\netstandard2.0\MathWorks.MATLAB.Types.dll</HintPath>
        </Reference>
      </ItemGroup>
    </Project>
    

    If you are using Microsoft Visual Studio for development, you can add the above dependencies from the Solution Explorer:

    • In Solution Explorer, right-click on the Dependencies node and choose Add Project Reference.

    • Browse for the assembly dependencies in the Reference Manager and add them.

Related Topics

External Websites