Sysprogs forums › Forums › VisualGDB › User Variables / Set an internal variable
- This topic has 7 replies, 2 voices, and was last updated 3 years, 1 month ago by ChangedDaily.
-
AuthorPosts
-
September 25, 2021 at 15:43 #31382ChangedDailyParticipant
Hi,
I have defined a User Variable called “FirmwareVersion”, given it a default value. I am then trying to use a Custom Build Step (“Before building”) to set a new value prior to build with the “x=set an internal variable” action. When I use the test the command it says the variable was set but the value does not get through to the build where it is referenced like this in the MSBuild settings:
VERSION_STRING=”\””$(FirmwareVersion)””\”
My goal is to have one place to set a firmware version string that can be used in the application code but also be used to append to the output filename, e.g. APP-V01.01.01.bin, and be common to multiple configurations.
The default value does find its way through to the application. I thought I was close!
Any help appreciated, thanks
September 27, 2021 at 08:55 #31389supportKeymasterHi,
Indeed, the MSBuild-level properties are separate from the VisualGDB variables and are not automatically inherited.
The easiest way to achieve what you have described is to programmatically generate an MSBuild property sheet defining the necessary variables. You can reference the property sheet from one or more projects, and can invoke the tool generating it as a custom pre-build step.
Another option would be to simply generate a header file with the relevant definitions, and include it from the projects.
September 29, 2021 at 09:09 #31419ChangedDailyParticipantHi,
Thanks, I have created a new property sheet which can be seen by multiple projects/configurations, that bit is working. I don’t understand how to ‘invoke a tool to generate it’ though. Please can you explain further?
Creating a header file with the version information is of course very easy but how can I use the definitions in the header file in VisualGDB?
Thanks
September 30, 2021 at 08:16 #31422ChangedDailyParticipantHi,
Actually going back to my original question, I created a “User Variable” in the VisualGDB settings. The default value is propogated to the build system OK but not updated in the “Before building” action. If the VisualGDB value is updated why is that not then set in the “VERSION_STRING” in my example?
Thanks
September 30, 2021 at 18:27 #31424supportKeymasterFor MSBuild projects, the VisualGDB-level variables should not be automatically propagated to MSBuild level, unless you configured some mechanism to do it manually. If you can share the screenshots of your setup (how you configured the variables and how do you observe them propagated), we will try to explain what is going on.
October 1, 2021 at 08:20 #31426ChangedDailyParticipantHi,
Please find attached screen shots of settings, I have not configured any special mechanism; set User Variable with a default value, then use it in the MSBuild settings page.
Thanks
Attachments:
You must be logged in to view attached files.October 2, 2021 at 10:02 #31430supportKeymasterThanks for the clarification. The user variables defined via VisualGDB Project Properties indeed work differently. Their values are saved to the .user file each time you edit them via VisualGDB Project Properties, and are read throughout the build process.
The variables set via custom build/debug steps only persist until the end of the corresponding operation. For non-MSBuild projects that would be the entire build. For MSBuild-based projects they are guaranteed to persist between multiple pre-build steps in the same sequence, but not between pre-build steps and the actual build.
October 6, 2021 at 09:56 #31453ChangedDailyParticipantHi,
I have managed to share a variable between VisualGDB and the MSBuild system by using an MSBuild Property sheet which is visible in all configurations and importing this sheet to VisualGDB settings.
Patrick
-
AuthorPosts
- You must be logged in to reply to this topic.