无法在Swift Package Manager中解析清单文件

问题描述 投票:0回答:1

我正在制作一个可在多个快速应用程序中使用的库。我希望可以通过Swift Package Manager轻松安装我的库。我创建了一个空白的Swift应用程序,并尝试使用Swift软件包管理器从Github存储库中自动安装此库。

[当我第一次尝试使用程序包管理器下载存储库时,收到一条错误消息,提示我需要使用path属性指定到我的sources文件夹的路径,所以我添加了这一行

path: "Sources"

指定目录。

这是我的项目根目录中的package.Swift文件

// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription

let package = Package(
    name: "TestProject",
    products: [
        // Products define the executables and libraries produced by a package, and make them visible to other packages.
        .library(
            name: "TestProject",
            targets: ["TestProject"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
    ],
    path: "Sources",
    targets: [
        // Targets are the basic building blocks of a package. A target can define a module or a test suite.
        // Targets can depend on other targets in this package, and on products in packages which this package depends on.
        .target(
            name: "TestProject",
            dependencies: []),
        .testTarget(
            name: "TestProjectTests",
            dependencies: ["TestProject"]),
    ]
)

自从将path: "Sources"添加到我的代码后,我现在收到两个新错误

类型“任何”没有成员“库”

未能解析清单文件

我不确定是什么原因导致这些错误,因为此代码(减去我添加的行)是由Swift生成的。

swift libraries swift5 swift-package-manager
1个回答
1
投票

您指定的path的目标不是整个软件包。

因此转到您的:

.target(
    name: "TestProject",
    dependencies: []),

并将其更改为:

.target(
    name: "TestProject",
    dependencies: [],
    path: "Sources"),

您可能需要做同样的事情才能使testTarget指向其测试源(默认情况下,它相对于软件包根目录的Tests/位置。

© www.soinside.com 2019 - 2024. All rights reserved.