06-01-2021 03:09 PM - edited 06-01-2021 03:10 PM
I'm trying to hard-code some version information into my application at build time. I want this version information to updated automatically (eg no manual changes required by the developer, the build system simply looks at the code to determine version info automatically), and also immutable, so should not be determined from a config file (since that could be modified after application deployment).
The solution I've implemented is to put the required data into a control, and as part of the pre-build action, update the default value of this control.
This has worked, but occasionally I get the following error: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000kEssSAE&l=en-US
The VI has changed on disk since last saved or loaded by LabVIEW. If you load its front panel, it will probably be inconsistent with the parts of the VI already in memory, resulting in a corrupt VI.
This seems to be because the prebuild action is *saving* the VI *during* the build process. The fix I've implemented is to have the pre-build action do it's VI saving, and then error out to cancel the build, and then when it notices the control is already updated, essentially to do nothing, but the error remains.
I'm stuck at this point, how do people do this?
I've attached the pre-build action I use, if that's helpful!
06-01-2021 03:33 PM
Set the desired version number in the build specification and use vi.lib\Platform\fileVersionInfo.llb\FileVersionInfo.vi to get the version from your exe. Following code should work:
06-01-2021 03:36 PM
The versioning used by LabVIEW is not the versioning scheme we intend to use. We need commit-level details in this control, so we need to do it in a different way.
06-01-2021 03:51 PM
I have done something similar for real-time and FPGA apps where existing versioning tools don't help. I used a global to store the version number, build date and time. Then updated the default values as part of the Pre-build. I've not had any issues with this method although for those apps I'm still back in 2016.
I did wrap up the global as a private member of a library with an API to get the values (called by the application) or to save new defaults (called by the Pre-build).
06-01-2021 05:45 PM
I have tested your VI by replacing the missing subVI by an hardcoded revision value and it worked just fine.
I would have done differently though. With scripting you can directly set the values of constants in the diagram.
Here is an example project where I modify a diagram constant in the prebuild of an executable :
06-01-2021 06:45 PM
Personally, I would prefer to use tags. Maybe something like this: