Cannot use MusicKit with SwiftPM

This is probably not the place to ask this question, but I'm not sure where else to ask...
I am building a CLI tool which would use MusicKit

Package.swift:

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

import PackageDescription

let package = Package(
    name: "Yatoro",
    dependencies: [
        .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"),
        .package(url: "https://github.com/apple/swift-log.git", from: "1.6.1"),
    ],
    targets: [
        .executableTarget(
            name: "Yatoro",
            dependencies: [
                .product(name: "ArgumentParser", package: "swift-argument-parser"),
                .product(name: "Logging", package: "swift-log"),
            ],
            linkerSettings: [
                .unsafeFlags([
                    "-Xlinker", "-sectcreate",
                    "-Xlinker", "__TEXT",
                    "-Xlinker", "__info_plist",
                    "-Xlinker", "Sources/Yatoro/Resources/Info.plist",
                ])
            ]
        ),
    ]
)

Info.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleName</key>
    <string>Yatoro</string>
    <key>CFBundleIdentifier</key>
    <string>mybundleidentifier.yatoro</string>
    <key>NSAppleMusicUsageDescription</key>
    <string>This app requires access to Apple Music to play music tracks.</string>
</dict>
</plist>

I have found this solution to include Info.plist into the SwiftPM build with the linker flags.

If I run it from Xcode the CLI app runs fine and I get the authorization prompt. But if I try to run Xcode built executable or the executable built with swift build from the command line it crashes on MusicAuthotization.request().
It's kind of frustrating, not really know when to look. Any advice?

The short answer is you can't build it with swift build as that builds a pure Swift package where you'd need to declare it as a dependency in your Package.swift file but there's nothing to import (since it's not open source). The easiest thing is to just build in as an Xcode app

Thanks! But how can I build it with an Xcode then to run the executable from terminal? The Xcode built executable is also crashing when I run it in the terminal

You should be able to get the binary created by Xcode and call that from the command line. (You can also set arguments by editing the scheme in Xcode for development). How to actually do that if the usual build and find the binary doesn't work I don't know I'm afraid as I'm a server dev! But the Apple Developer forums may be more useful for a question like that

Thanks anyway, that was helpful!

UPD:
Solved by manually adding terminals and the CLI app itself in System Settings > Privacy & Security > Media & Apple Music