Extracting the current package version from an SPM compiled library?

In Alamofire, we build a dynamic user agent for every request. Part of this string is the version of Alamofire currently being used. When compiled as a dynamic framework this can easily be extracted using the Bundle APIs and the Info.plist. However, when compiled statically, especially through SPM, this method returns the containing bundle's info (usually the app itself). Is there any way to extract this info when built this way? Is there a solution that works for all build types? I'd prefer something automatic, rather than something I need to bump for every release.

There is not even a way to specify a package version within a revision, let alone query it. (Externally you can query Git for tags and such, but that means you need the repository around, so it only really works at development time.)

If you use generate-xcodeproj and look inside it, you will see that SwiftPM provides generic Info.plist files to all frameworks and labels them version 1.0 no matter what.

I keep a constant in the source code and bump it manually. (And sometimes I make mistakes and end up with mislabelled releases. Don’t tell anyone. :stuck_out_tongue:)

Terms of Service

Privacy Policy

Cookie Policy