Accessing the app version from .prj file

16 Ansichten (letzte 30 Tage)
Mike Thompson
Mike Thompson am 30 Dez. 2015
Bearbeitet: dpb am 1 Jan. 2023
I am using the Matlab Application Compiler. Its GUI gives the option to enter the version of my application, along with some other information:
This is written to the .prj file when one clicks "Save Project."
I would like to access this information from within my program so that I can display it in a help dialog and on my output (e.g. "generated with version 1.23"). How can this be accomplished (without including the .prj file in my distribution and parsing it to extract this information)?
  1 Kommentar
dpb am 1 Jan. 2023
Bearbeitet: dpb am 1 Jan. 2023
Revising earlier comment, the .prj file does contain the updated version number after saving, but the version displayed in the user dialog if reopen via the "Share" button in AppDesigner, always revertes back to 1.0. Most annoying!
With R2020b...

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Tomas Åhlman
Tomas Åhlman am 21 Sep. 2020
As far as I've been able to determine this information is still not easily accessible in the Appdesigner.
I have been able to find the version information of an installed app in a file of the installation folder. By installed app I here refer to a MATLAB app that's run through MATLAB. Not actually stand alone.
By parsing this file it's possible to read the information at runtime. Here's an example, MATLAB 2019a is used:
appPath = mfilename('fullpath'); % Finds the path of currently executed file
[p, ~] = fileparts(appPath); % Removes the filename, keeps the path
if(isfolder([p filesep 'resources' filesep])) % Double checks that folder "resources" exist
xmlLocation = [p filesep 'resources' filesep 'addons_core.xml']; % Filename of the .xml file
appInfo = xml2struct(xmlLocation); % Parses xml
for i = 1:length(appInfo.Children)
if strcmpi(appInfo.Children(i).Name, 'version') % searches for token "version"
app.APPversion = appInfo.Children(i).Children.Data; % reading data for token "version"
app.APPversion = 'debug'; % if no folder "./resources" app is likely run from appdesigner - debug mode
This method has so far only been verified to use on installed MATLAB apps, that uses the MATLAB interpretor. I don't know if the same resources is available on a stand alone compilation.
Best of luck, and let's hope that the dev team soon fixes this issue
  2 Kommentare
Brian am 16 Nov. 2021
I adapted yours and developed the below yesterday and it has seemed to work so far.
function ver = CheckVersion(~)
if isdeployed % If compiled and deployed
[~, result] = system('path');
p = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once')); % Get run path
myDir=dir(fullfile(p,'..','appdata','components')); % Move to components folder and get all files
myDir=myDir(3:end); % Exclude '.' and '..'
validFile=myDir(datetime({})==max(datetime({}))); % Only look at most recent install, includes 'common' and 'platform'
appInfo=xml2struct(fullfile(validFile(1).folder,validFile(1).name)); % Import 'common' as struct from xml (requires xml2struct download)
ver=appInfo.componentData.component.componentVersion.Text; % Grab the version number as a char array
fullpath=mfilename('fullpath'); % Get run path
if ~isempty(strfind(fullpath,s.matlab.addons.InstallationFolder.ActiveValue)) % If the run path includes the addons install folder, it is run from the app bar
[p,~]=fileparts(fullpath); % Get the path
if isfolder(fullfile(p,'resources'))
xmlLocation=fullfile(p,'resources','addons_core.xml'); % Go to resources folder
appInfo=xml2struct(xmlLocation); % Import addons_core.xml as struct
ver=appInfo.addonCore.version.Text; % Grab the version number as a char array
ver='debug'; % This may be redundant with below. Left in to prevent errors just in case...
else % If run from MATLAB mlapp file
As far as the *.prj file goes, the version number can be found by importing the xml as above and using:
Hope this helps!
dpb am 30 Dez. 2022
AFAICT, the .prj file doesn't retain the version number from one invocation to another for the same's always "1.0". Most annoying!
If you open the compiler, change the version number to 2.0, say, then Save the project file and close, if reopen via the "Share" button in AppDesigner, the version will have reverted back to 1.0.
With R2020b...

Melden Sie sich an, um zu kommentieren.

Tushar Athawale
Tushar Athawale am 4 Jan. 2016
When installing a standalone application using web installer on deployment machine, it initially displays the application version number. For example, in the following image, the version number for application 'numb.exe' is 1.0.
Currently, there is, however, no way to extract the version number of application after installing it using the web installer. I have informed the developers regarding this enhancement and they might consider including it in a future release.
One workaround to this issue could be to include the following command in your MATLAB script and then compiling it to a standalone application:
>> h = msgbox('Version number: your_app_version_number');
This will display a message box containing version number of application on a deployment machine.
Alternatively, you can also include a code in your MATLAB script to write a text file which contains information regarding author, version and so on. For that, you can use the "fprintf" command in MATLAB.
  1 Kommentar
Joris Lambrecht
Joris Lambrecht am 4 Mai 2018
I am trying to do the same thing in R2017b. It looks like the version # shows up in the install folder C:/Program Files/MyCompany/MyApp/appdata/components and products folders. Those contain xml files for all the versions that have been installed though, so I'm not sure how you know which one it is using. I am guessing this is captured in the files/MyApp_manifest.bin file but I don't know how to read that.
I can of course write the version code somewhere in the App, but then I have to make sure to update both version numbers.

Melden Sie sich an, um zu kommentieren.


Mehr zu MATLAB Compiler finden Sie in Help Center und File Exchange


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by