{"id":14151,"date":"2023-04-21T13:15:17","date_gmt":"2023-04-21T17:15:17","guid":{"rendered":"https:\/\/blogs.mathworks.com\/simulink\/?p=14151"},"modified":"2023-04-21T13:15:17","modified_gmt":"2023-04-21T17:15:17","slug":"referenced-projects","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2023\/04\/21\/referenced-projects\/","title":{"rendered":"Referenced Projects"},"content":{"rendered":"<div class = rtcContent><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Today I want to talk about <\/span><a href = \"https:\/\/www.mathworks.com\/help\/simulink\/componentization-of-large-projects.html\"><span>Referenced Projects<\/span><\/a><span>. They can be very useful to componentize a large project, allowing for modular work, component reuse, unit testing, etc.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Working in technical support and interacting with users from all kinds of industries, I often see MATLAB Projects referencing 20, 50, or even 100 projects. Obviously, not all those are organized the same way.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>In this post, I will describe the main types of setups I see. I would like to hear your thoughts in the comments below on your preferred way to organize referenced projects and why. I also created a <\/span><a href = \"https:\/\/www.mathworks.com\/matlabcentral\/discussions\/highlights\/784158-how-do-you-prefer-to-organize-referenced-projects\"><span>poll<\/span><\/a><span> that you should see on the left of this post. <\/span><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>Absolute Path<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>To add a referenced project to your current project, start by clicking on the References button in the Project toolstrip:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/referencedProjects_1-2.png\" width = \"843\" height = \"149\" alt = \"\" style = \"vertical-align: baseline; width: 843px; height: 149px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>This will open the Add Reference dialog and allow you to select the reference type. Let's start with one that I don't see being used very often: Absolute.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/referencedProjects_2-2.png\" width = \"486\" height = \"318\" alt = \"\" style = \"vertical-align: baseline; width: 486px; height: 318px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>As the dialog says, you must ensure that the location is available to all users. This can be useful to include a utility project for which all users in the company need to use the same version, stored in a network location available to all users.<\/span><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>Relative<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>A more common way of organizing referenced projects is to specify their location <\/span><span style=' font-weight: bold;'>relative<\/span><span> to the top project. Among the projects we ship as examples and projects I receive from users, I typically see two types of relative setup:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/referencedProjects_3-2.png\" width = \"750\" height = \"336\" alt = \"\" style = \"vertical-align: baseline; width: 750px; height: 336px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Let's see the implications associated with those two architectures.<\/span><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>Relative - Outside<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>If you look at the example <\/span><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2023a\/simulink\/slref\/referencing-projects-from-a-simulink-project.html?s_tid=doc_srchtitle\"><span>Work with Referenced Projects<\/span><\/a><span>, you will notice that it references two projects. If you select either of the two, you will see that they are both in a relative location that begins with \"..\/\", meaning that they are stored in a folder beside the main project top folder:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/referencedProjects_4-2.png\" width = \"889\" height = \"157\" alt = \"\" style = \"vertical-align: baseline; width: 889px; height: 157px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>With this setup, you will not see the files from the referenced projects in the \"Files\" view:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/referencedProjects_5-2.png\" width = \"892\" height = \"169\" alt = \"\" style = \"vertical-align: baseline; width: 892px; height: 169px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Instead, you can go to the References view and click the Show\/Hide Files button on the top right to view the files for the selected referenced project:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/referencedProjects_6-2.png\" width = \"890\" height = \"175\" alt = \"\" style = \"vertical-align: baseline; width: 890px; height: 175px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>This setup can be useful if multiple referenced projects are themselves referencing a common project. Placing all the projects side by side allows the common referenced project to be referenced using \"..\/\" by multiple projects. Here is a screenshot from the <\/span><a href = \"https:\/\/www.mathworks.com\/products\/powertrain.html\"><span>Powertrain Blockset<\/span><\/a><span> example <\/span><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2023a\/autoblks\/ug\/conventional-vehicle-reference-application.html\"><span>Conventional Vehicle Reference Application<\/span><\/a><span> where the project <\/span><span style=' font-family: monospace;'>VehicleConfig<\/span><span> is referenced four times.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/referencedProjects_7-2.png\" width = \"691\" height = \"375\" alt = \"\" style = \"vertical-align: baseline; width: 691px; height: 375px;\"><\/img><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>Relative - Inside<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Another approach is to include referenced projects using a relative path, but inside the main project. This is in fact necessary if you want to <\/span><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2023a\/simulink\/slref\/organize-project-into-components-using-submodules.html?s_tid=doc_srchtitle#OrganizeProjectsIntoComponentExample-3\"><span>reference a project as a Git Submodule<\/span><\/a><span>.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>If your project is under <\/span><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2023a\/simulink\/ug\/set-up-git-source-control.html\"><span>Git source control<\/span><\/a><span> and you would like to include a referenced project stored in a separate repository, you can do it using <\/span><a href = \"https:\/\/git-scm.com\/book\/en\/v2\/Git-Tools-Submodules\"><span>submodules<\/span><\/a><span>. Begin by clicking on the Submodules icon on the toolstrip:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/referencedProjects_8-2.png\" width = \"475\" height = \"89\" alt = \"\" style = \"vertical-align: baseline; width: 475px; height: 89px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>In the submodules window, click Add and you will see that the submodule path must be inside the main project:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/referencedProjects_9-2.png\" width = \"807\" height = \"469\" alt = \"\" style = \"vertical-align: baseline; width: 807px; height: 469px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Once the submodule has been added to the project, you can then add it as a referenced project using the same steps as described at the beginning of this post:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/referencedProjects_10-2.png\" width = \"467\" height = \"318\" alt = \"\" style = \"vertical-align: baseline; width: 467px; height: 318px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>One thing I like when using a relative path inside the main project is that I can see all the files in the main project window, including the files in the referenced projects. As you can see, the Status and Git columns have icons indicating that those files are in referenced projects and submodules.<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/referencedProjects_11-1.png\" width = \"624\" height = \"314\" alt = \"\" style = \"vertical-align: baseline; width: 624px; height: 314px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Another advantage of placing the projects you want to reference inside the main project folder is that we can identify if they have not been configured as referenced projects properly. For that, use the <\/span><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2023a\/matlab\/ref\/matlab.project.project.runchecks.html\"><span style=' font-family: monospace;'>runChecks<\/span><\/a><span> function or click on the <\/span><a href = \"https:\/\/www.mathworks.com\/help\/releases\/R2023a\/matlab\/matlab_prog\/use-source-control-with-projects.html#btcdu4u-1\"><span style=' font-weight: bold;'>Check Project<\/span><\/a><span style=' font-weight: bold;'> <\/span><span>button in the Tools gallery of the project window. (Tip: I made the Check Project button a favorite, so it shows up at the top of the gallery)<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/referencedProjects_12-1.png\" width = \"501\" height = \"190\" alt = \"\" style = \"vertical-align: baseline; width: 501px; height: 190px;\"><\/img><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>If we find projects in sub-folders inside your project that are not marked as referenced projects, we will let you know and offer to fix it in one click:<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><img class = \"imageNode\" src = \"https:\/\/blogs.mathworks.com\/simulink\/files\/referencedProjects_13.png\" width = \"802\" height = \"274\" alt = \"\" style = \"vertical-align: baseline; width: 802px; height: 274px;\"><\/img><\/div><h2  style = 'margin: 20px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; '><span>Now it's your turn<\/span><\/h2><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>I would really like to hear your opinion on this type of project componentization choices. Are you on team \"Outside\" or team \"Inside\"? Or maybe you found the perfect combination of both?<\/span><\/div><div  style = 'margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(0, 0, 0); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left; '><span>Take a few seconds to respond to <\/span><a href = \"https:\/\/www.mathworks.com\/matlabcentral\/discussions\/highlights\/784158-how-do-you-prefer-to-organize-referenced-projects\"><span>the poll<\/span><\/a><span> on the left of this post and share your thoughts in the comments below.<\/span><\/div>\r\n<\/div><script type=\"text\/javascript\">var css = ''; var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); head.appendChild(style); style.type = 'text\/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); }<\/script>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/simulink\/files\/referencedProjects_7-2.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>Today I want to talk about Referenced Projects. They can be very useful to componentize a large project, allowing for modular work, component reuse, unit testing, etc.Working in technical support and... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2023\/04\/21\/referenced-projects\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":14484,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[24,654],"tags":[660,378],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/14151"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=14151"}],"version-history":[{"count":11,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/14151\/revisions"}],"predecessor-version":[{"id":14496,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/14151\/revisions\/14496"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media\/14484"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=14151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=14151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=14151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}