Swift 包管理器存在资源编译错误

Swift Package Manager with resources compile errors

我正在尝试使用我的 Package.swift 文件中的资源:

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

import PackageDescription

let package = Package(
    name: "MyPackage",
    products: [
        .library(
            name: "MyPackage",
            targets: ["MyPackage"])
    ],
     targets: [
        .target(
            name: "MyPackage",
            resources: [
               .process("Resources/one.xml"),
               .process("Resources/two.json"),
               .process("Resources/three.json"),
             ]
        )
        .testTarget(
            name: "MyPackageTests",
            dependencies: ["MyPackage"]
        )
    ]
)

当我在另一个项目中导入和编译包时,出现很多错误,例如:

Cannot infer contextual base in reference to member 'target'

或:

Reference to member 'process' cannot be resolved without a contextual type

这些文件位于 Sources -> MyPackage -> Resources 中我的包项目中

我也试过.copy("Resources/one.xml"),等等

我错过了什么?

您在 target 右括号后遗漏了一个 ,

        .target(
            name: "BioSwift",
            resources: [
               .process("Resources/unimod.xml"),
               .process("Resources/aminoacids.json"),
               .process("Resources/elements.json"),
               .process("Resources/enzymes.json"),
               .process("Resources/functionalgroups.json"),
               .process("Resources/hydropathy.json")
            ]
        ), // Here is the missed `,`

另外,您不需要一个一个地添加文件!相反,您可以添加一个目录:

.process("Resources")