Getting Started with the %COMPONENT_NAME% .NET Assembly

MATLAB® Compiler SDK™ lets you create Microsoft® .NET components from MATLAB code that can be integrated with applications written in C#. While creating .NET components you can optionally generate sample application code in C# that can be used to integrate and test the generated component. You can use this guide to set up your environment and build and run your sample driver application.

Location of Installed .NET Assembly Files

View %COMPONENT_NAME% Files
%SAMPLE_LINK%

Location of .NET Project Dependencies

If MATLAB is installed on your system:
If MATLAB Runtime is installed on your system:

Prerequisites

  1. Verify that you have met all the MATLAB Compiler SDK™ .NET target requirements. For details, see MATLAB Compiler SDK .NET Target Requirements.
  2. End users must have an installation of MATLAB Runtime to run the application. For details, see Install and Configure MATLAB Runtime. For testing purposes, you can use an installation of MATLAB instead of MATLAB Runtime.

Integrate MATLAB Code Into .NET Application

After creating your .NET component using MATLAB® Compiler SDK™, you can integrate it into any .NET application. This example uses an assumed sample C# application code created during build. If generated, you can use this sample .NET application code as a guide to write your own application.
  1. At the system command prompt, type:
  2. dotnet new console --name %COMPONENT_NAME%
    This creates a folder named %COMPONENT_NAME% that has the following contents:
  3. Open the project file in a text editor and add the following references to the project using the <ItemGroup> tag:
  4. MathWorks.MATLAB.Runtime.dll
    MathWorks.MATLAB.Types.dll
    Once you add the references, your project file should resemble the following:
    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net6.0</TargetFramework>
      </PropertyGroup>
      <ItemGroup>
        <Reference Include="MathWorks.MATLAB.Runtime">
          <HintPath>%DEFAULT_RUNTIME_LOCATION%%RUNTIME_DLL_PATH%</HintPath>
        </Reference>
        <Reference Include="MathWorks.MATLAB.Types">
          <HintPath>%DEFAULT_RUNTIME_LOCATION%%TYPES_DLL_PATH%</HintPath>
        </Reference>
      </ItemGroup>
    </Project>
  5. Replace the C# source file Program.cs with the sample file %SAMPLE1%.cs
  6. At the command line, build your .NET project by typing:
  7. dotnet build %COMPONENT_NAME%.csproj
  8. At the command line, run your application by typing:
  9. dotnet run

Additional Resources

Deploy MATLAB Code Within .NET Application Using MATLAB Data API for .NET
Handle MATLAB Data in .NET Applications