Main Content

dotnetenv

Change .NET default environment

Since R2022b

    Description

    MATLAB® supports loading these .NET assemblies:

    • .NET, including .NET Core (Microsoft® Windows®, macOS, and Linux®)

    • .NET Framework (Windows only)

    For details, see System Requirements for Using MATLAB Interface to .NET. For information about .NET versions compatible with MATLAB, see MATLAB Interfaces to Other Languages.

    To determine if your system has a supported version, use the NET.isNETSupported function. To change the .NET Runtime environment, call dotnetenv.

    ne = dotnetenv returns details about the current .NET Runtime environment as a NETEnvironment object.

    ne = dotnetenv(env) changes the default .NET Runtime environment used to load .NET assemblies in MATLAB. The run-time environment is initialized when you call functions in either NET or System packages. If .NET is already loaded, restart MATLAB before using this syntax.

    example

    ne = dotnetenv(env,Name=Value) specifies parameters for setting the .NET Runtime environment. For example, you can specify the numerical .NET version for "core" applications and the target frameworks to load.

    example

    Examples

    collapse all

    Check if .NET is already loaded. You might have to restart MATLAB.

    e = dotnetenv;
    if e.Status=="loaded"
        disp("To change the environment, restart MATLAB then call dotnetenv.")
    end

    Set the .NET Runtime environment to the latest version.

    e = dotnetenv("core")
    e = 
      NETEnvironment with properties:
    
                Runtime: core
                 Status: loaded
                Version: ".NET 7.0.10"
        RuntimeLocation: "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.10\"
    

    Suppose that you have .NET versions 6.0.5 and 6.0.3 installed.

    Set the .NET Runtime environment to .NET 6.0.5, which is more recent than .NET 6.0.3.

    ne = dotnetenv("core",Version="6");

    Suppose that you have .NET versions 6.0.5 and 6.0.3 installed.

    Set the .NET Runtime environment to .NET 6.0.3.

    ne = dotnetenv("core",Version="6.0.3");

    Input Arguments

    collapse all

    .NET Runtime environment, specified as one of these values.

    • "core" — Change the default .NET Runtime environment to the latest version of .NET. To set the .NET Runtime environment to a specific version of .NET, use the Version name-value argument.

    • "framework" — Change the default .NET Runtime environment to the .NET Framework (Microsoft Windows only).

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: ne = dotnetenv("core",Version="8",Frameworks=["Microsoft.WindowsDesktop.App","Microsoft.AspNetCore.App"]);

    Since R2025a

    .NET version number for "core" applications, specified as a string scalar or character vector in one of the following formats. For more information, see Select the .NET version to use in the Microsoft documentation.

    • major — The function chooses the latest minor and patch version. For example, if Version="8" and the system has versions 8.0.0 and 9.0.0, the function uses 8.0.0. This option is equivalent to the LatestMinor roll-forward setting.

    • major.minor — The function chooses the latest patch version. This option is equivalent to the LatestPatch roll-forward setting.

    • major.minor.patch — The function chooses the exact patch version. This option is equivalent to the Disable roll-forward setting.

    Example: ne = dotnetenv("core",Version="8")

    Example: ne = dotnetenv("core",Version="6.0.3")

    Since R2025a

    Target frameworks to load, specified as a string array.

    Example: ne = dotnetenv("core",Version="8",Frameworks="Microsoft.WindowsDesktop.App");

    Version History

    Introduced in R2022b

    expand all