My current project has some editor scripts that I run just prior to run/build, which dynamically creates some game objects in my main scene based on configuration. I don't want these objects to clutter up version control however, so I delete them prior to saving the project and committing changes to the repo. Currently I'm doing both of these steps manually, but this seems like the kind of thing that should automated. Is there a way to automate running these scripts prior to a Build and then deleting the constructed objects (presumably can create another script to help with this) prior to saving the project?
I don't know if it'll work for your specific use case, but note that there's the PostProcessBuild attribute for editor scripts that run automatically after a build. I use that to edit the XCode project generated by an iOS "build".
Another approach is to write a script that executes the build, and that script can probably do cleanup after a build too. Like, I routinely write editor scripts that add a "Custom Build" option to the File menu, and then that script does a bunch of stuff before calling BuildPlayer. Assuming the BuildPlayer method is synchronous (I don't know if it is, I've never tested this) then that script could also do more stuff after BuildPlayer.