SPM Resources only in debug configuration

Very excitied to try out SPM resources support!

I was wondering if there was any way to exclude certain assets from the release configuration of a package? I was hoping to exclude my “Preview Assets.xcassets” catalog.

The exclude option seemed promising, but there doesn’t appear to be a way to condition it. I don’t think you can use #if DEBUG in a Package.swift. Is there anything like BuildSettingCondition, but for resources?


I have the same question !

1 Like

This isn't supported right now, but sounds like an interesting future direction to explore.

Ah, gotcha! Wondering if there’s at least a workaround to suggest for now.

What if these resources were placed in a separate target? Are there any tricks for conditionally linking two targets between dev and release configurations?

If you put them in a separate target and forward them with public accessors, then the main target could put #if DEBUG around the import, and use dependencies: [.target(..., condition: .when(configuration: .debug))] in the manifest to prevent it from being included in the product.

That sounds useful! But I couldn't seem to get it working. It appears that TargetDependencyCondition only supports .when(.platforms), but no .configuration.

Interesting. I hadn’t tried it myself. I copied and pasted from the text of SE‐0273. Maybe its implementation is incomplete? Or it was accepted with revisions that never made it back into the document? @NeoNacho was review manager.

Yep, it is, only the platform part is implemented. It was incorrectly updated to fully implemented, let me fix that.

Updated the status to

Partially implemented (Swift 5.3 supports platform conditionals, but not configuration conditionals)



When you search the evolution proposals, it still shows up as Implemented: https://apple.github.io/swift-evolution/#?search=Package%20Manager%20Conditional%20Target%20Dependencies
But maybe that can't be fixed?

What is important is - is this feature still being tracked somewhere, or is it falling through the cracks?

1 Like

Friendly bump.

1 Like

@NeoNacho what is the state on this matter? What is currently blocking implementation?


This post outlines a use case that I'm also actively seeking: The ability to share stub-like data between tests in a package and Xcode previews in an app -- without having to include that said data in release builds.

Terms of Service

Privacy Policy

Cookie Policy