XcodeGen引入本地Swift Package时出现"Missing package product"错误(指向xcodeproj而非包目录)
Hey there, let's work through this XcodeGen + Swift Package Manager issue you're hitting. From what you shared, you're trying to pull in a local Swift Package called 'Core' into your XcodeGen-generated project, but Xcode can't resolve it correctly—plus it seems like it's pointing to the .xcodeproj instead of the actual package directory, right? You mentioned using Cursor IDE to build the project too, so let's break this down step by step.
First, let's recap what you've already confirmed:
- Your
project.ymlincludes the Core package definition, and thePackage.swiftat the specified path is valid - When you right-click the Core entry in "Frameworks, Libraries, and Embedded Content", there's an issue (sounds like it's linking to the wrong location or failing to find the package product)
Common Fixes to Try:
Double-check your project.yml package reference
Make sure you're pointing directly to the folder containing thePackage.swift(not the .xcodeproj) in yourproject.yml. The correct setup should look like this:packages: Core: path: ./Core # 指向包含Package.swift的目录,不是Core.xcodeprojThen, in your target dependencies, confirm you're referencing the exact product name from the Core package:
targets: MyAppTarget: dependencies: - package: Core product: Core # 必须和Package.swift里定义的product名称一致Clear Xcode's Derived Data
Xcode loves hanging onto old cache, which often causes weird package resolution glitches. Head toXcode > Settings > Locations, click the arrow next to Derived Data to open the folder, then delete everything inside. Restart Xcode, then regenerate your project withxcodegen generate.Validate your Core package's Package.swift
Make sure thePackage.swiftfor your Core package defines a product that matches what you're referencing inproject.yml. For example:let package = Package( name: "Core", products: [ .library( name: "Core", // 这个名称要和project.yml里的product字段完全匹配 targets: ["Core"]), ], targets: [ .target(name: "Core"), ] )Regenerate your project from scratch
Stale generated files can cause issues. Runxcodegen cleanfirst to delete the existing .xcodeproj, then runxcodegen generateagain to create a fresh project. Open the new project and check if the Core package resolves properly.Sync Cursor IDE with the updated project
Since you're using Cursor, make sure it's synced with the latest generated project. Try closing and reopening Cursor, or refreshing the project structure. IDEs can sometimes hold onto old cache that doesn't reflect the latest XcodeGen changes.
If None of the Above Work:
- Try manually adding the Core package to Xcode via
File > Add Packages > Add Local.... If this works, compare the manual setup with what XcodeGen generated to spot any discrepancies in references. - Double-check for typos in paths, package names, or product names—small mistakes here are super common and easy to miss!
备注:内容来源于stack exchange,提问作者Dario

