无法使用 Swift 4 包管理器导入包

Can't import packages using Swift 4 Package Manager

尝试在我的机器上使用 Xcode-beta (v9) 测试 Swift 4,但在将包导入测试项目时遇到问题:

Package.swift

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

import PackageDescription

let package = Package(
    name: "sampleproject",
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
        .package(url: "https://github.com/IBM-Swift/Kitura.git", from: "1.7.6"),
        .package(url: "https://github.com/Alamofire/Alamofire.git", from: "4.5.0")
    ],
    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: "sampleproject",
            dependencies: []),
    ]
)

Compile Swift Module 'investprosto' (1 sources) /Users/username/Projects/sampleproject/Sources/sampleproject/main.swift:1:8: error: no such module 'Kitura' import Kitura ^ error: terminated(1): /Applications/Xcode- beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift- build-tool -f /Users/username/Projects/sampleproject/.build/debug.yaml

Dependencies 虚拟文件夹包含具有相同包名的目录,但它们是空的。但是,.build\checkouts.build\repositories 包含包文件夹和相应的文件。

我的系统配置中是否缺少某些内容?

原来我还必须将依赖项包含到 Package.swift 的 .target 中:

.target(named: "sampleproject", dependencies: ["Kitura", "Alamofire"])

并再次构建项目。

即使您需要将 target 添加到 Package.swift 中,但有时这还不够。我通过删除 .build 目录和文件 Package.resolved,然后 运行 swift build 或从 Xcode[=23 构建来解决这个问题=].构建命令没有获取包,因为它已经在 resolved 文件中,但是如果你删除 .build 目录,它就变得毫无意义。您可以通过检查 Xcode 中的 Dependencies 目录来验证它,如果出现 No such package/module

之类的错误,它将为空