Accessing the app version from .prj file
19 次查看(过去 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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/152955/image.png)
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 个评论
回答(2 个)
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
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
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
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/172436/image.png)
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:
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
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!