Accessing the app version from .prj file

16 次查看(过去 30 天)
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 个评论
dpb
dpb 2023-1-1
编辑:dpb 2023-1-1
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...

请先登录,再进行评论。

回答(2 个)

Tomas Åhlman
Tomas Åhlman 2020-9-21
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.
./resources/addons_core.xml
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"
break;
end
end
app.APPversion = appInfo.Children(i).Children.Data; % reading data for token "version"
else
app.APPversion = 'debug'; % if no folder "./resources" app is likely run from appdesigner - debug mode
end
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 个评论
Brian
Brian 2021-11-16
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({myDir.date})==max(datetime({myDir.date}))); % 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
else
fullpath=mfilename('fullpath'); % Get run path
s=settings;
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
else
ver='debug'; % This may be redundant with below. Left in to prevent errors just in case...
end
else % If run from MATLAB mlapp file
ver='debug';
end
end
end
As far as the *.prj file goes, the version number can be found by importing the xml as above and using:
appInfo.deployment_dash_project.configuration.param_dot_version.Text
Hope this helps!
dpb
dpb 2022-12-30
AFAICT, the .prj file doesn't retain the version number from one invocation to another for the same project....it'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...

请先登录,再进行评论。


Tushar Athawale
Tushar Athawale 2016-1-4
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 个评论
Joris Lambrecht
Joris Lambrecht 2018-5-4
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Install Products 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by