Xcode 15.3 zaps Swift packages: here’s how you fix it

I have cd "${PROJECT_DIR}" ; agvtool bump set as a script in a number of my macOS projects’ Xcode schemas’ Build phases. The second of the two commands auto-increments the project build number on completion of the build. It continues to do so, but with Xcode 15.3* there’s a side-effect: it deletes the project’s Swift packages.

Xcode and Swift icons
Icons owned by Apple

The upshot is that, having built the application, in order to successfully build it again I must first manually resolve the project’s package versions in order to get them back. If I forget to do so, subsequent builds fail because the packages are missing.

Actually, what’s missing is the Package.resolved file, deep with the project’s .xcodeproj file. For some reason, I learned by Googling today, agvtool has taken to deleting it. If I remove my auto-increment script, that Swift package record file remains in place.

So I have to manually update build numbers — which is quicker than manually restoring Swift packages — every build, right? Fortunately not. The solution is to add a further command to the script, after agvtool:

cd "${PROJECT_DIR}"
agvtool bump
xcodebuild -resolvePackageDependencies

This jack-hammer-to-crack-the-nut auto-restores Package.resolved right after argvtool has deleted it. I can now continue running builds without having to worry.

*More accurately, the Xcode Command Line Tools suite.