Can the pluginWorkingDirectory contain an asset catalog - spoiler it can!

I now generate a colors.xcassets catalog from a variable json file. It is a buildTool that runs whenever the json changes.

This correctly puts the folder into the pluginWorkingDirectory but when I build it there seams to be no way to add this resource as a resource to the library I'm building?

I get the warning when I use swift 5.6

no rule to process file '~/Library/Developer/Xcode/DerivedData/<#package#-uuid/SourcePackages/plugins/<#package#>.output/<#library#>/<#pluginName#>/color-lizard.xcassets/colorGreen40/Contents.json' of type 'file' for architecture 'arm64'

I now managed to fix all issues using swift 5.7 and have a working example

doozMen/swift-generated-asset-plugin: Shows how to generate an asset catalog that can load colors into a SwiftUI view from the plugin working directory

I hope this helps somebody facing similar issues

Seams to be a known issue [SR-15935] Resource files created by build tool plugins aren't handled properly · Issue #4345 · apple/swift-package-manager

I can confirm that if you set swift version to 5.7 or more that it solves the issue. Thanks to @NeoNacho for clarifying that.

1 Like

I created a repo with working code for generating asset catalogs. doozMen/swift-generated-asset-plugin: Just an example for a feature request

The problem remains that you apparently have to use a prebuild command that is ran all the time. I would like to ran this only when files in the target are changed. But as far as I understand it this is only possible using a build command?

@NeoNacho should I create a feature request for that or is there another way to do the above?

What problem are you seeing using .buildCommand(...)?

Ok so I seam to have fixed my issue. My problem was I was feeding a assets.xcassets catalog file by file to the output files of the build command. This caused duplicate build commands as everything is called Content.json in the end.

If anybody else struggles with this I created a minimal swift package with a SwiftUI view that loads colors from generated assets here

doozMen/swift-generated-asset-plugin: Shows how to generate an asset catalog that can load colors into a SwiftUI view from the plugin working directory