"Missing package product" error – inconsistency between command-line and Xcode

I am encountering a strange "Missing package product '(package name)' error that manifests only in Xcode, but not in the command-line. How should I make the Package.swift to behave the same in both environments?

I encountered the problem while prototyping multiple libraries (products: [.library(...),.library(...)...]) within a single package and wanting to use them from another package. I tried to isolate the problem into two new empty packages and it behaves the same with the new packages as it does with my original – the issue seems to be replicable.

Having the following directory layout :

SOME_ROOT/
    MyTool/
        Package.swift
        ...
    ProtoLib/
        Package.swift
        Sources/
             MyCore/
             MyFlows/
        ...

The MyTool Package.swift looks like:

// swift-tools-version: 5.9
import PackageDescription

let package = Package(
    name: "MyTool",
    platforms: [.macOS("13"), .custom("linux", versionString: "1")],
    products: [
        .library(
            name: "MyTool",
            targets: ["MyTool"]),
    ],
    dependencies: [
        .package(path: "../ProtoLib"),
    ],

    targets: [
        .target(
            name: "MyTool",
            dependencies: [
                .product(name: "MyCore", package: "ProtoLib"),
                .product(name: "MyFlows", package: "ProtoLib"),
            ]
        ),
        .testTarget(
            name: "MyToolTests",
            dependencies: ["MyTool"]),
    ]
)

The prototyped library ProtoLib package looks like this:

// swift-tools-version: 5.9

import PackageDescription

let package = Package(
    name: "ProtoLib",
    platforms: [.macOS("13"), .custom("linux", versionString: "1")],
    products: [
        
        .library(
            name: "MyCore",
            targets: ["MyCore"]),
        .library(
            name: "MyFlows",
            targets: ["MyFlows"])
    ],
    targets: [
        .target(
            name: "MyCore"),
        .target(
            name: "MyFlows",
            dependencies: ["MyCore"])
    ]
)

The ProtoLib has two libraries that are incubated for the time being under one package (multiple reasons, mostly convenience).

When I build the project using command-line swift everything is fine, the project builds without any issues. When I try to build the MyTool project using Xcode I am getting two errors:

  • .../MyTool/Package.swift Missing package product 'MyCore'
  • .../MyTool/Package.swift Missing package product 'MyFlows'

What I am doing wrong here?


Versions:

  • swift version (command-line): swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1) Target: arm64-apple-macosx13.0
  • XCode: Version 15.0 (15A240d)

(Posted also on Apple Dev forums, as I am not sure whether this is XCode only issue or rather Swift/Swift PM issue. My apologies if this is just Xcode/Apple tooling issue and it does not belong to these forums.)

Seems like this was a bug in XCode 15.0. Works as expected in XCode Version 15.1 beta (15C5028h).