gpt4 book ai didi

swift - 为什么我不能使用 Swift 包管理器将 SwiftPM 用作依赖项?

转载 作者:行者123 更新时间:2023-12-04 00:20:41 35 4
gpt4 key购买 nike

我有以下 Package.swift:

// swift-tools-version:5.2
import PackageDescription

let package = Package(
name: "my-vapor-project",
platforms: [
.macOS(.v10_15)
],
dependencies: [
// 💧 A server-side Swift web framework.
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0-rc"),
.package(url: "https://github.com/vapor/fluent.git", from: "4.0.0-rc"),
.package(url: "https://github.com/vapor/fluent-mysql-driver.git", from: "4.0.0-rc"),
.package(url: "https://github.com/apple/swift-package-manager", .branch("master")),
],
targets: [
.target(name: "App", dependencies: [
.product(name: "Fluent", package: "fluent"),
.product(name: "FluentMySQLDriver", package: "fluent-mysql-driver"),
.product(name: "Vapor", package: "vapor"),
.product(name: "SwiftPM", package: "swift-package-manager")
]),
.target(name: "Run", dependencies: ["App"]),
.testTarget(name: "AppTests", dependencies: [
.target(name: "App"),
.product(name: "XCTVapor", package: "vapor"),
])
]
)

当我保存文件时,Xcode 会尝试自动解析依赖项,并收到以下错误和警告:

Showing All Messages /Users/sluther/Projects/my-vapor-project/Package.swift: product dependency 'SwiftPM' in package 'swift-package-manager' not found

: dependency 'SwiftPM' is not used by any target

最佳答案

事实证明,在撰写本文时,使用 Swift Tools 5.2 版时无法将 Swift Package Manager 作为依赖项包含在内,该版本删除了用于定义产品依赖项的旧语法。将 Swift Tools 版本切换到 5.1 解决了该问题。

// swift-tools-version:5.1
import PackageDescription

let package = Package(
name: "my-vapor-project",
platforms: [
.macOS(.v10_15)
],
dependencies: [
// 💧 A server-side Swift web framework.
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0-rc"),
.package(url: "https://github.com/vapor/fluent.git", from: "4.0.0-rc"),
.package(url: "https://github.com/vapor/fluent-mysql-driver.git", from: "4.0.0-rc"),
.package(url: "https://github.com/apple/swift-package-manager", .branch("master")),
],
targets: [
.target(name: "App", dependencies: [
.product(name: "Fluent", package: "fluent"),
.product(name: "FluentMySQLDriver", package: "fluent-mysql-driver"),
.product(name: "Vapor", package: "vapor"),
"SwiftPM"
]),
.target(name: "Run", dependencies: ["App"]),
.testTarget(name: "AppTests", dependencies: [
.target(name: "App"),
.product(name: "XCTVapor", package: "vapor"),
])
]
)

关于swift - 为什么我不能使用 Swift 包管理器将 SwiftPM 用作依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60943858/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com