How do I add swift-argument-parser to a command line target on an existing Xcode project?

100 Views Asked by At

I am trying to add a Mac command line tool target to an existing SwiftUI project, and use the swift-argument-parser framework in that command line tool.

I get build errors after adding the swift-argument-parser to my project.

Here are the minimum reproducible example steps that trigger this problem:

  1. Create new Multiplatform app “Test”
  2. File>New>Target macOS command line tool named “TestCmd”
  3. Select Scheme “TestCmd” and verify that it runs successfully.
  4. Select TestCmd target
  5. File>Add Package dependencies>swift-argument-parser Add both ArgumentParser and generate-manual packages to TestCmd target
  6. Run from TestCmd scheme.

This yields a whole stream of errors:

Library not loaded: @rpath/ArgumentParser.framework/Versions/A/ArgumentParser

Reason: tried: ‘~/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/ArgumentParser.framework/Versions/A/ArgumentParser' (no such file), ‘~/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' (code signature in <9CBB1F37-8A3F-32FC-9744-3108CEF0D6A5> ‘~/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs), '~/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' (code signature in <9CBB1F37-8A3F-32FC-9744-3108CEF0D6A5> '~/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs), '/System/Volumes/Preboot/Cryptexes/OS~/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' (no such file), '~/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' (code signature in <9CBB1F37-8A3F-32FC-9744-3108CEF0D6A5> '~/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs), '/System/Volumes/Preboot/Cryptexes/OS~/Library/Developer/Xcode/DerivedData/Test-hjtkgtqoywzwinaakrcdvgycyxhx/Build/Products/Debug/PackageFrameworks/ArgumentParser.framework/Versions/A/ArgumentParser' (no such file)

Searching on the string "not valid for use in process: mapping process and mapped file (non-platform) have different Team IDs" yields some posts about signing a Mac product for distribution on Apple's developer forums.

I will eventually want to code sign the command line tool target so I can share it/distribute it on the App Store, but for now, I just want to develop the @#$@#$ command locally.

Question: How do I add the swift-argument-parser SPM package to my nascent command line tool so I can start writing my command?

I can upload the above minimum project to GitHub if it would be helpful, but it takes less than a minute to reproduce the errors above.

(I'm using Xcode 15.0, running on an M2 Mac with macOS Sonoma 14.0, if that matters.)

0

There are 0 best solutions below