Main Content

matlab.project.Project

Project object

Description

The matlab.project.Project object represents the currently loaded project. Use the project object to programmatically manipulate the project, interact with source control, and find file dependencies.

Creation

To create a matlab.project.Project object, use the currentProject function to get the currently open project. For example:

proj = currentProject;
If no project is currently open, use the openProject function to load an existing project. For example:
proj = openProject("C:/workSpace/project1/");
To create and open a blank project and get the project object, use the matlab.project.createProject function. For example:
proj = matlab.project.createProject;

Properties

expand all

Project name, specified as a string scalar.

Project description, specified as a string scalar.

Path of project root folder, specified as a string scalar.

This property is read-only.

Top-level status, stored as a logical 1 (true) if the project is a top-level project.

This property is read-only.

Project permission status, stored as a logical 1 (true) if the project has limited permissions when using add, remove, and create object functions. A referenced project status is always read-only to prevent modification.

Project definition file types, specified as an array of DefinitionFilesType objects. Use matlab.project.convertDefinitionFiles to change the current project definition file type programmatically.

This property is read-only.

Project repository location, stored as a string scalar.

This property is read-only.

Source control integration type, stored as a string scalar.

Example: "Git"

Paths of project files, specified as an array of ProjectFile objects. This property changes when you add or remove project files. You can use addFile, addFolderIncludingChildFiles, or removeFile to add or remove project files.

Shortcut files for project, specified as an array of Shortcut objects. This property changes when you add or remove shortcut files. You can use addShortcut and removeShortcut to create or remove shortcut files programmatically.

Label categories for project, specified as an array of Category objects. This property changes when you create or remove label categories. You can use createCategory and removeCategory to create and remove label categories programmatically.

Graph of dependencies between project files, specified as a digraph object.

Project startup files, specified as a string array. This property changes when you add or remove startup files. You can use addStartupFile and removeStartupFile to add or remove startup files programmatically.

Project shutdown files, specified as a string array. This property changes when you add or remove shutdown files. You can use addShutdownFile and removeShutdownFile to add or remove shutdown files programmatically.

Project path folders that are added to the MATLAB® path, specified as an array of PathFolder objects.

Paths of referenced projects, specified as an array of ProjectReference objects. This property changes when you add or remove reference projects. You can use addReference and removeReference to add or remove reference projects programmatically.

Path of the project startup folder, specified as a string scalar.

Path of Simulink® cache folder, specified as a string scalar.

Path of Simulink Coder™ code generation folder, specified as a string scalar.

Path of dependency analysis cache file, specified as a string scalar.

Object Functions

expand all

currentProjectGet current project
openProjectLoad an existing project
isLoadedDetermine if project is loaded
reloadReload project
closeClose project
exportExport project to archive
matlab.project.createProjectCreate blank project
matlab.project.convertDefinitionFilesChange definition file type of project
matlab.project.deleteProjectStop folder management and delete project definition files
matlab.project.loadProjectLoad project
matlab.project.rootProjectGet root project
addFileAdd files or folders to project
addFolderIncludingChildFilesAdd folders and child files to project
removeFileRemove file or folder from project
addPathAdd folder to project path
removePathRemove folder from project path
addReferenceAdd referenced project to project
listAllProjectReferencesList all projects in reference hierarchy of current project
listShutdownIssuesList all issues that occur when project closes
listStartupIssuesList all issues that occur when project opens
removeReferenceRemove project reference
addStartupFileAdd startup file to project
addShutdownFileAdd shutdown file to project
removeStartupFileRemove file from project startup files
removeShutdownFileRemove file from project shutdown files
addShortcutAdd shortcut to project
removeShortcutRemove shortcut from project
addLabelAttach label to project files
createLabelCreate project label
removeLabelRemove label from project
findLabelGet project file label
createCategoryCreate category of project labels
findCategoryFind project category of labels
removeCategoryRemove project category of labels
findFilesFind project files by category or label name
listModifiedFilesList modified files in project
listRequiredFilesGet files required by specified project files
listImpactedFilesGet files impacted by changes to specified project files
listAllProjectReferencesList all projects in reference hierarchy of current project
refreshSourceControlUpdate source control status of project files
runChecksRun all project checks
updateDependenciesUpdate project dependencies
matlab.project.isUnderProjectRootDetermine whether file or folder is under project root folder
matlab.project.isFileInProjectDetermine whether file or folder belongs to project

Examples

collapse all

Download the Times Table App project by clicking the button. The example project is under Git source control.

Alternatively, run the following command:

openExample("matlab/TimesTableProjectExample")

Open the Times Table App project and use the currentProject function to create a project object that you can manipulate programmatically.

openExample("matlab/TimesTableProjectExample")
proj = currentProject
proj = 

  Project with properties:

                        Name: "Times Table App"
                 Description: "This example project contains the source code and tests for a simple educational app. ↵↵Use the project shortcuts to get started with this project."
                  RootFolder: "C:\Workspace\Projects\TimesTableApp"
                    TopLevel: 1
                    ReadOnly: 0
         DefinitionFilesType: FixedPathMultiFile
    SourceControlIntegration: "Git"
          RepositoryLocation: "C:Workspace\Projects\repositories\TimesTableApp"
                       Files: [1×13 matlab.project.ProjectFile]
                   Shortcuts: [1×4 matlab.project.Shortcut]
                  Categories: [1×3 matlab.project.Category]
                Dependencies: [1×1 digraph]
                StartupFiles: [1×0 string]
               ShutdownFiles: [1×0 string]
                 ProjectPath: [1×2 matlab.project.PathFolder]
           ProjectReferences: [1×0 matlab.project.ProjectReference]
         SimulinkCacheFolder: ""
        ProjectStartupFolder: "C:\Workspace\Projects\TimesTableApp"
       SimulinkCodeGenFolder: ""
         DependencyCacheFile: ""

Open the Times Table App project and create a project object.

openExample("matlab/TimesTableProjectExample")
proj = currentProject;

Find the functions that you can execute on the project object.

methods(proj)
Methods for class matlab.project.Project:

addFile                          findFiles                       removeLabel
addFolderIncludingChildFiles     isLoaded                        removePath
addLabel                         istAllProjectReferences         removeReference
addPath                          listImpactedFiles               removeShortcut
addReference                     listModifiedFiles               removeShutdownFile
addShortcut                      listRequiredFiles               removeStartupFile
addShutdownFile                  listShutdownIssues              runChecks
addStartupFile                   listStartupIssues               updateDependencies
close                            refreshSourceControl
createCategory                   reload
export                           removeCategory
findCategory                     removeFile

Methods of matlab.project.Project inherited from handle.                      

Get a project object, and examine its properties.

Open the Times Table App project. Use currentProject to create a project object from the currently loaded project.

openExample("matlab/TimesTableProjectExample")
proj = currentProject;

Examine the project files.

files = proj.Files
files = 

  1×13 ProjectFile array with properties:

    Path
    Revision
    SourceControlStatus
    Labels

Examine the labels of the 13th file.

proj.Files(13).Labels
ans = 

  Label with properties:

            File: "C:\Workspace\Projects\TimesTableApp\utilities\runTheseTests.m"
        DataType: "none"
            Data: []
            Name: "Design"
    CategoryName: "Classification"

Get a particular file by name.

myfile = findFiles(proj,"source/timesTableGame.m",OutputFormat="ProjectFile")
myfile = 

  ProjectFile with properties:

                   Path: "C:\Workspace\Projects\TimesTableApp\source\timesTableGame.m"
               Revision: "a089d00d667d39be7940fcdcac18a9ca7a3c6840"
    SourceControlStatus: Unmodified
                 Labels: [1×1 matlab.project.Label]

Find out what you can do with the file.

methods(myfile)
Methods for class matlab.project.ProjectFile:

addLabel     findLabel    removeLabel  

Methods of matlab.project.ProjectFile inherited from handle.

Version History

Introduced in R2019a