Package .NET Assemblies from Command Line
You can package .NET assemblies at the MATLAB® prompt or your system prompt using either of these commands.
deploytool
invokes the Library Compiler app to create a compiler project.mcc
invokes the MATLAB Compiler™ to create a deployable application at the command prompt.
Execute Compiler Projects with deploytool
The deploytool
command has two flags that invoke one of the compiler apps
to package an already existing project without opening a window.
-build
— Invoke the correct compiler app to build the project but not generate an installer.project_name
-package
— Invoke the correct compiler app to build the project and generate an installer.project_name
For example, deploytool -package magicsquare
generates
the binary files defined by the magicsquare
project
and packages them into an installer that you can distribute to others.
Create .NET Assemblies with mcc
The mcc
command invokes MATLAB
Compiler to create a .NET assembly at the command prompt and provides
fine-level control while packaging the application. It does not package the results
in an installer.
The following command defines the complete mcc
command syntax
with all required and optional arguments used to create a .NET assembly. Brackets
indicate optional parts of the syntax.
mcc -W
'dotnet:
[component_name
,class_name
,
0.0|framework_version
,
Private|Encryption_Key_Path,local|remote' file1
[file2
...fileN
]class{
[class_name
:file1
[,file2
,...,fileN
]},...-d
output_dir_path
] -T
link:lib
.NET Bundle
You can simplify the command line used to create .NET assemblies. To do so,
use the bundle named dotnet
. Using this bundle still requires
that you pass in the five parts (including local|remote
) of
the -W
argument text string; however, you do not have to
specify the -T
option.
The following example creates a .NET assembly called
mycomponent
containing a single .NET class named
myclass
with methods foo
and
bar
.
mcc -B 'dotnet:mycomponent,myclass,2.0, encryption_keyfile_path,local' foo.m bar.m
In this example, the compiler uses the .NET Framework version 2.0 to package
the component into a shared assembly using the key file specified in
encryption_keyfile_path
to sign the shared component.
Creating a .NET Namespace
The following example creates a .NET assembly from two MATLAB files foo.m
and
bar.m
.
mcc -B 'dotnet:mycompany.mygroup.mycomponent,myclass,0.0,Private,local' foo.m bar.m
The example creates a .NET assembly named mycomponent
that
has the following namespace: mycompany.mygroup
. The component
contains a single .NET class myclass
, which contains methods
foo
and bar
.
To use myclass
, place the following statement in your
code:
using mycompany.mygroup;
Adding Multiple Classes to an Assembly
The following example creates a .NET assembly that includes more than one
class. This example uses the optional class{...}
argument to
the mcc
command.
mcc -B 'dotnet:mycompany.mycomponent,myclass,2.0,Private,local' foo.m bar.m class{myclass2:foo2.m,bar2.m}
The example creates a .NET assembly named mycomponent
with
two classes:
myclass
has methodsfoo
andbar
myclass2
has methodsfoo2
andbar2
See NET.isNETSupported
to check for
a supported version of Microsoft® .NET framework.
Differences Between Compiler Apps and Command Line
You perform the same functions using the compiler apps, a compiler.build
function, or the mcc
command-line interface. The interactive menus and
dialog boxes used in the compiler apps build mcc
commands that are
customized to your specification. As such, your MATLAB code is processed the same way as if you were packaging it using
mcc
.
If you know the commands for the type of application you want to deploy and do not require
an installer, it is faster to execute either compiler.build
or
mcc
than go through the compiler app workflow.
Compiler app advantages include:
You can perform related deployment tasks with a single intuitive interface.
You can maintain related information in a convenient project file.
Your project state persists between sessions.
You can load previously stored compiler projects from a prepopulated menu.
You can package applications for distribution.