Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic script before compilation (Read 193 times)
Pablo
Newbies
*
Offline


Posts: 5
Joined: Mar 14th, 2023
script before compilation
Sep 21st, 2025 at 7:02pm
Print Post  
Hello

I've been trying to add compilation events to Visual Studio. Apparently, Visual Micro isn't using these events because it uses a non-standard compiler. I want to run a script before the program is compiled, that is, before the files that are later compiled are copied to the buffer. The script automatically generates code related to the project and must be included in the compilation. My attempts with Arduino Custom Build Events and Hooks haven't been successful because the files were copied before execution. I only achieved something similar by manually copying the file into the buffer folder in the script. This only partially solved the problem because, depending on the settings, these Arduino events may be in use, causing them to run inconsistently. For example, when I included a custom partition table, my script stopped calling because the number was already in use for that event by the partition table.
Is there a way to automatically run a script before copying files, whether from Visual Micro, Visual Studio, or a third party?
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2789
Joined: Feb 13th, 2019
Re: script before compilation
Reply #1 - Sep 22nd, 2025 at 9:03am
Print Post  
Thanks for the report.

From your description the below video should show how this can work (where values are injected into the code which is subsequently compiled):
Video: https://youtu.be/jQ8O9Hi3cDA
Demo Project: https://www.visualmicro.com/downloads/VerifiableBoardFirmware.zip

Quote:
For example, when I included a custom partition table, my script stopped calling because the number was already in use for that event by the partition table.

In this scenario you need to increase your hook number to be beyond any standard hooks in use in the toolchain.

If you can attach your complete build output as a text file with the below options enabled (and your custom hook added), we will be able to advise further:
vMicro > Compiler > Verbose
vMicro > Compiler > Show Build Properties
  
Back to top
IP Logged
 
Acuario
Senior Member
****
Offline


Posts: 258
Location: Spain
Joined: Aug 28th, 2015
Re: script before compilation
Reply #2 - Sep 22nd, 2025 at 4:21pm
Print Post  
I have a script that runs to update a version number in a header file that is run before the project is compiled. I have the following command in the board.txt file

# Increment version before build
recipe.hooks.sketch.prebuild.1.pattern=cmd.exe /c {build.project_path}\version.bat {build.project_path}\fwversion.h

In my case this runs the version.bat script to update fwversion.h, which is in my project, before the files are copied and compiled, but I guess the script could be anything.

If you have a script that can prepare everything for compilation then running it this way should do what you want.

Maybe this is what you are looking for?

The contents of my version.bat file is as follows (if of interest)
@echo off
setlocal EnableDelayedExpansion
set file=%1

for /F "tokens=1-3 delims=N " %%a in (%file%) do (
   for %%A in (%%a %%b %%c) do set "i=%%A"
)
set /a i=i+1
echo #define FWVERSION %i% > %file%


  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2789
Joined: Feb 13th, 2019
Re: script before compilation
Reply #3 - Sep 22nd, 2025 at 4:23pm
Print Post  
Thanks for the detail and it sounds very similar to the demo we have.

If you can attach the compilation log requested in the previous post we will be able to confirm what needs altering to ensure this works on your setup.
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint