# Explore Plugin API in Swift Package Manager

By [foxsin10](https://paragraph.com/@foxsin10) · 2022-05-11

---

随着 Swift 5.6 的发布，Swift Package Manager 的 Plugin API 也一并发布。同时相关开发人员也提供了[Example Project](https://github.com/abertelrud/swiftpm-buildtool-plugin-examples) 。

项目本身可以正常运行，通过运行 swift build/run 命令即可，但是还存在很多问题，比如[这些](https://forums.swift.org/tag/plugins)。

同时，Plugin 的实现中的 command 并不是每次 build(每次运行 swift build/run 命令) 都会执行，除非 \`Package.swift\` 文件在 build 之前触发保存或者修改，相关问题也在[这里](https://github.com/apple/swift-package-manager/issues/5476)。

PS: 目前在 Plugin 中，想要如代码开发阶段去打印一些变量，可以通过 `Diagnostics` 去做输出，如图，每次编译成功都会把 `Diagnostics` 的文本输出 issue navigator 栏

![](https://storage.googleapis.com/papyrus_images/e7c90281558dd6b91aa563f0b37575bd70c003f3f75914ffe3fc6571f0766daa.png)

---

*Originally published on [foxsin10](https://paragraph.com/@foxsin10/explore-plugin-api-in-swift-package-manager)*
