主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

compiler.package.installer

MATLAB Compiler 生成的文件创建安装程序

说明

compiler.package.installer(results) 使用由 compiler.build 函数生成的 compiler.build.Results 对象 results 创建一个安装程序。

示例

compiler.package.installer(results,Name,Value) 使用 compiler.build.Results 对象 results 创建一个安装程序,并使用一个或多个 名称-值参量指定附加选项。

示例

compiler.package.installer(results,"Options",opts) 使用 compiler.build.Results 对象 resultsInstallerOptions 对象 opts 指定的安装程序选项创建一个安装程序。如果您使用 InstallerOptions 对象,则不能使用名称-值参量指定任何其他选项。

示例

compiler.package.installer(files,filePath,"ApplicationName",appName)mcc 命令生成的文件创建一个安装程序。安装的应用程序名称由 appName 指定。安装程序文件扩展名由运行该函数的操作系统决定。

示例

compiler.package.installer(files,filePath,"ApplicationName",appName,Name,Value)mcc 命令生成的文件创建一个安装程序。安装的应用程序名称由 appName 指定。可以使用可选的名称-值参量自定义安装程序。

示例

compiler.package.installer(files,filePath,"Options",opts) 使用 InstallerOptions 对象 opts 指定的安装程序选项为 mcc 命令生成的文件创建安装程序。如果您使用 InstallerOptions 对象,则不能使用名称-值参量指定任何其他选项。

示例

示例

全部折叠

使用 compiler.build.standaloneApplication 函数的结果为独立应用程序创建安装程序。

在 MATLAB® 中,找到要部署为独立应用程序的 MATLAB 代码。对于此示例,使用 matlabroot\extern\examples\compiler 中的 magicsquare.m 文件编译。

appFile = fullfile(matlabroot,"extern","examples","compiler","magicsquare.m");

使用 compiler.build.standaloneApplication 命令编译独立应用程序。

results = compiler.build.standaloneApplication(appFile);

使用 compiler.package.installer 函数为独立应用程序创建安装程序。

compiler.package.installer(results);
该函数在名为 MyAppInstaller 的文件夹中生成一个名为 magicsquareinstaller 的安装程序。

应用程序的默认安装文件夹是目标计算机上 %ProgramFiles% 环境变量的值。

使用 compiler.build.standaloneApplication 函数的结果为独立应用程序创建安装程序,并使用名称-值参量对其进行自定义。

保存位于 magicsquare.m 的文件 matlabroot\extern\examples\compiler 的路径。

appFile = fullfile(matlabroot,"extern","examples","compiler","magicsquare.m");

使用 compiler.build.standaloneApplication 命令编译独立应用程序。

results = compiler.build.standaloneApplication(appFile);

使用 Results 对象的 compiler.package.installer 函数为独立应用程序创建一个安装程序。使用名称-值参量指定安装程序名称并在安装程序中包含 MATLAB Runtime

compiler.package.installer(results,...
    "InstallerName","MyMagicInstaller",...
    "RuntimeDelivery","installer");
该函数在名为 MyMagicInstaller 的文件夹中生成一个名为 magicsquareinstaller 的安装程序。

使用 compiler.build.standaloneApplication 函数的结果为 Windows® 系统上的独立应用程序创建安装程序。使用 InstallerOptions 对象自定义安装程序。

保存位于 magicsquare.m 的文件 matlabroot\extern\examples\compiler 的路径。

appFile = fullfile(matlabroot,"extern","examples","compiler","magicsquare.m");

使用 compiler.build.standaloneApplication 命令编译独立应用程序。

results = compiler.build.standaloneApplication(appFile);

创建一个 InstallerOptions 对象。使用名称-值参量指定应用程序名称、作者公司、作者姓名、安装程序名称和摘要。

opts = compiler.package.InstallerOptions(results,...
    "ApplicationName","MagicSquare_Generator",...
    "AuthorCompany","Boston Common",...
    "AuthorName","Frog",...
    "InstallerName","MagicSquare_Installer",...
    "Summary","Generates a magic square.")
opts = 

  InstallerOptions with properties:

           RuntimeDelivery: "web"
           InstallerSplash: "C:\Program Files\MATLAB\R2025a\toolbox\compiler\packagingResources\default_splash.png"
             InstallerIcon: "C:\Program Files\MATLAB\R2025a\toolbox\compiler\packagingResources\default_icon_48.png"
             InstallerLogo: "C:\Program Files\MATLAB\R2025a\toolbox\compiler\packagingResources\default_logo.png"
               PackageType: "auto"
           AdditionalFiles: {}
     AddRemoveProgramsIcon: "C:\Program Files\MATLAB\R2025a\toolbox\compiler\packagingResources\default_icon_48.png"
                AuthorName: "Frog"
               AuthorEmail: ""
             AuthorCompany: "Boston Common"
                   Summary: "Generates a magic square."
               Description: ""
         InstallationNotes: ""
                  Shortcut: "D:\Work\magicsquarestandaloneApplication\magicsquare.exe"
                   Version: "1.0"
             InstallerName: "MagicSquare_Installer"
           ApplicationName: "MagicSquare_Generator"
                 OutputDir: ".\MagicSquare_Generatorinstaller"
    DefaultInstallationDir: "C:\Program Files\MagicSquare_Generator"
                   Verbose: "off"

使用 ResultsInstallerOptions 对象作为 compiler.package.installer 函数的输入,为独立应用程序创建安装程序。

compiler.package.installer(results,"Options",opts);
该函数在名为 MagicSquare_Installer 的文件夹中生成一个名为 MagicSquare_Generatorinstaller 的安装程序。

为 Windows 系统上的独立应用程序创建安装程序。

编写一个生成幻方的 MATLAB 函数。将该函数保存在名为 mymagic.m 的文件中。

function out = mymagic(in)
out = magic(in)

使用 mcc 命令编译独立应用程序。

mcc -m mymagic.m
mymagic.exe
mccExcludedFiles.log
readme.txt
requiredMCRProducts.txt

使用 compiler.package.installer 函数为独立应用程序创建安装程序。

compiler.package.installer("mymagic.exe",...
    "D:\Documents\MATLAB\work\MagicSquare\requiredMCRProducts.txt",...
    "ApplicationName","MagicSquare_Generator")
该函数在名为 MyAppInstaller.exe 的文件夹中生成一个名为 MagicSquare_Generatorinstaller 的安装程序。

使用名称-值参量自定义独立应用程序的安装程序。

使用 compiler.build.standaloneApplication 命令编译独立应用程序。

appFile = fullfile(matlabroot,"extern","examples","compiler","magicsquare.m");
buildResults = compiler.build.standaloneApplication(appFile);

保存生成的 requiredMCRProducts.txt 文件的路径。

runtimeProducts = fullfile(buildResults.Options.OutputDir,"requiredMCRProducts.txt")

保存独立应用程序构建结果的文件列表。

fileList = buildResults.Files

(可选)您可以通过修改 fileList 向安装程序添加其他文件。附加文件与应用程序可执行文件一起安装在安装目录中。

fileList = [fileList; {"UsageNotes.txt"}];

使用 compiler.package.installer 函数为独立应用程序创建安装程序。

compiler.package.installer(fileList, runtimeProducts,...
    "ApplicationName","CustomMagicSquare",...
    "InstallerName","Installer_With_Addl_Files",...
    "Summary","See UsageNotes.txt for info.")

使用 InstallerOptions 对象自定义 Windows 系统上独立应用程序的安装程序。

创建一个 InstallerOptions 对象。

opts = compiler.package.InstallerOptions("ApplicationName","MagicSquare_Generator",...
    "AuthorCompany","Boston Common",...
    "AuthorName","Frog",...
    "InstallerName","MagicSquare_Installer",...
    "Summary","Generates a magic square.")
opts = 

  InstallerOptions with properties:

           RuntimeDelivery: "web"
           InstallerSplash: "C:\Program Files\MATLAB\R2025a\toolbox\compiler\packagingResources\default_splash.ico"
             InstallerIcon: "C:\Program Files\MATLAB\R2025a\toolbox\compiler\packagingResources\default_icon_48.ico"
             InstallerLogo: "C:\Program Files\MATLAB\R2025a\toolbox\compiler\packagingResources\default_logo.png"
               PackageType: "auto"
           AdditionalFiles: {}
     AddRemoveProgramsIcon: ""
                AuthorName: "Frog"
               AuthorEmail: ""
             AuthorCompany: "Boston Common"
                   Summary: "Generates a magic square."
               Description: ""
         InstallationNotes: ""
                  Shortcut: ""
                   Version: "1.0"
             InstallerName: "MagicSquare_Installer"
           ApplicationName: "MagicSquare_Generator"
                 OutputDir: ".\MagicSquare_Generator"
    DefaultInstallationDir: "C:\Program Files\MagicSquare_Generator"
                   Verbose: "off"

InstallerOptions 对象作为输入传递给函数。

compiler.package.installer("mymagic.exe","requiredMCRProducts.txt","Options",opts)

输入参数

全部折叠

构建结果,指定为 compiler.build.Results 对象。通过保存 compiler.build 函数的输出来创建 Results 对象。

要安装的文件和文件夹列表,指定为字符向量、字符串标量、字符向量元胞数组或字符串数组。这些文件通常由 mcc 命令或 compiler.build 函数生成,还可以包含已安装应用程序运行所需的任何其他文件和文件夹。附加文件与应用程序可执行文件一起安装在安装目录中。

  • 可以使用同一版本的 compiler.package.installer 函数打包在特定版本中生成的文件。

  • 只要构建命令和 compiler.package.installer 函数来自同一版本,一个操作系统上的 .ctf 类型的文件就可以使用另一个操作系统上的 compiler.package.installer 函数进行打包。

示例: {"mymagic.exe","UsageNotes.txt"}

数据类型: char | string

MATLAB Compiler™ 生成的 requiredMCRProducts.txt 文件的路径。

示例: "D:\Documents\MATLAB\work\MagicSquare\requiredMCRProducts.txt"

数据类型: char | string

已安装的应用程序的名称,指定为字符向量或字符串标量。

示例: "MagicSquare_Generator"

数据类型: char | string

安装程序选项,指定为 InstallerOptions 对象。

名称-值参数

全部折叠

Name1=Value1,...,NameN=ValueN 的形式指定可选参量对组,其中 Name 是参量名称,Value 是对应的值。名称-值参量必须出现在其他参量之后,但对各个参量对组的顺序没有要求。

如果使用的是 R2021a 之前的版本,请使用逗号分隔每个名称和值,并用引号将 Name 引起来。

示例: "Version","9.5" 指定已安装应用程序的版本。

自 R2023a 起

要与应用程序一起安装的附加文件和文件夹,指定为字符向量、字符串标量、字符串数组或字符向量元胞数组。路径可以是相对于当前工作目录的路径,也可以是绝对路径。

示例: "AdditionalFiles",["myimage.png","data.mat"]

数据类型: char | string | cell

自 R2023a 起

添加或删除程序图标,指定为字符向量或字符串标量。该图像用作设置中 Windows 应用程序列表中的图标。路径可以是相对于当前工作目录的路径,也可以是绝对路径。

默认路径为:

"matlabroot\toolbox\compiler\packagingResources\default_icon_48.png"

示例: "AddRemoveProgramsIcon","win_icon.png"

数据类型: char | string

已安装应用程序的名称,指定为字符向量或字符串标量。

示例: "ApplicationName","MagicSquare_Generator"

数据类型: char | string

创建应用程序的公司名称,指定为字符向量或字符串标量。

示例: "AuthorCompany","Boston Common"

数据类型: char | string

应用程序作者的电子邮件地址,指定为字符向量或字符串标量。

示例: "AuthorEmail","frog@example.com"

数据类型: char | string

应用程序作者的姓名,指定为字符向量或字符串标量。

示例: "AuthorName","Frog"

数据类型: char | string

您希望安装程序安装应用程序的默认目录,指定为字符向量或字符串标量。

若未指定路径,则各个操作系统的默认路径为:

操作系统默认安装目录
WindowsC:\Program Files\appName
Linux®/usr/appName
macOS/Applications/appName

示例: "DefaultInstallationDir","C:\Users\MW_Programs\MagicSquare_Generator"

数据类型: char | string

应用程序的详细描述,指定为字符向量或字符串标量。

示例: "Description","The MagicSquare_Generator application generates an n-by-n matrix constructed from the integers 1 through n2 with equal row and column sums."

数据类型: char | string

有关使用应用程序的其他要求的说明,指定为字符向量或字符串标量。

示例: "InstallationNotes","This is a Linux installer."

数据类型: char | string

用作已安装应用程序的图标的图像文件的路径,指定为字符向量或字符串标量。

默认路径为:

"matlabroot\toolbox\compiler\packagingResources\default_icon_48.png"

示例: "InstallerIcon","D:\Documents\MATLAB\work\images\myIcon.png"

用作安装程序徽标的图像文件的路径,以字符向量或字符串标量形式指定。该徽标将调整大小为 112 像素 x 290 像素。

默认路径为:

"matlabroot\toolbox\compiler\packagingResources\default_logo.png"

示例: "InstallerLogo","D:\Documents\MATLAB\work\images\myLogo.png"

安装程序文件的名称,指定为字符向量或字符串标量。扩展名由执行该函数的操作系统决定。

示例: "InstallerName","MagicSquare_Installer"

用作安装程序启动屏幕的图像文件的路径,以字符向量或字符串标量指定。启动画面图标大小将调整为 400 像素 x 400 像素。

默认路径为:

"matlabroot\toolbox\compiler\packagingResources\default_splash.png"

示例: "InstallerSplash","D:\Documents\MATLAB\work\images\mySplash.png"

自 R2025a 起

要包含在安装程序中的可选 MATLAB Runtime 依赖项,指定为以下选项之一:

  • "all" - 使用此选项可将所有可选依赖项包含在安装程序中,包括图形化支持。此选项是默认行为。

  • "none" - 使用此选项则不会将任何可选依赖项包含在安装程序中。使用此选项可最大程度减小生成的安装程序的大小。

示例: "RuntimeDelivery","installer"

数据类型: char | string

保存安装程序的文件夹路径,指定为字符向量或字符串标量。

若未指定路径,则各个操作系统的默认路径为:

操作系统默认安装目录
Windows.\appNameinstaller
Linux./appNameinstaller
macOS./appNameinstaller

上面列出的目录中的 . 代表当前工作目录。

示例: "OutputDir","D:\Documents\MATLAB\work\MagicSquare"

自 R2024a 起

选择生成的安装程序的文件类型。

  • "auto" - 安装程序在创建安装程序时自动选择合适的包类型的选项。如果安装程序大小为 2GB 或更大,则安装程序将打包为 ZIP 文件。这是默认选项。

  • "zip" - 创建新安装程序时生成 ZIP 文件作为输出的选项。只有 Windows 才支持此选项。

示例: "PackageType","zip"

数据类型: char | string

自 R2024a 起

MATLAB Runtime 交付选项,指定为下列之一:

  • "web" - 安装程序在应用程序安装期间从 MathWorks® 网站下载 MATLAB Runtime 的选项。此选项是默认行为。

  • "installer" - 在安装程序中包含 MATLAB Runtime 的选项,以便可以在应用程序安装期间安装它,而无需连接到 MathWorks 网站。如果您认为最终用户可能无法访问互联网,请使用此选项。

  • "none" - 在应用程序安装期间不安装 MATLAB Runtime 的选项。如果您认为最终用户将使用其他方法安装 MATLAB Runtime,请使用此选项。 (自 R2024a 起)

注意

如果您使用 "web""installer" 选项,则会安装完整的 MATLAB Runtime要创建可运行一个或多个特定 MATLAB Compiler (自 R2024b 起) 应用程序的最小 MATLAB Runtime 安装程序,请参阅 compiler.runtime.customInstaller

示例: "RuntimeDelivery","installer"

数据类型: char | string

安装程序在安装时将创建快捷方式的文件或文件夹的路径,指定为字符向量或字符串标量。

示例: "Shortcut",".\mymagic.exe"

数据类型: char | string

应用程序的摘要说明,指定为字符向量或字符串标量。

示例: "Summary","Generates a magic square."

数据类型: char | string

已安装应用程序的版本号,指定为字符向量或字符串标量。

示例: "Version","2.0"

数据类型: char | string

自 R2023b 起

用于控制输出详细程度的标志,指定为 "on""off",或者指定为数字或逻辑值 1 (true) 或 0 (false)。值 "on" 等效于 true,值 "off" 等效于 false。因此,可以将此属性的值用作逻辑值。该值存储为 matlab.lang.OnOffSwitchState 类型的 on/off 逻辑值。

  • 如果将此属性设置为 "on",则 MATLAB 命令行窗口将显示进度信息,指示打包过程中的编译器输出。

  • 如果将此属性设置为 "off",则命令行窗口不会显示进度信息。这是默认行为。

示例: "Verbose","on"

数据类型: logical

提示

  • 此函数创建的安装程序将安装 MATLAB Compiler 生成的工件以及(可选)完整的 MATLAB Runtime。要创建可运行一个或多个特定 MATLAB Compiler 应用程序的最小 MATLAB Runtime 安装程序,请参阅 compiler.runtime.customInstaller

版本历史记录

在 R2020a 中推出

全部展开