Change package at build-time?

Hello,

I have two tarball packages, one for development and one for release.
I wish to change which package is in the project at build-time (using development package when making release build results in compilation errors).

I’ve tried using UnityEditor.PackageManager.Client in OnPreprocessBuild, but the package is resolved/changed AFTER the build fails.

Ideally it should also work in batch mode.

Any help would be much appreciated!

Cheers,
Daniel