How to exclude a local package from an Xcode target?

The way canImport works is if the module exists in your search paths, it'll be true. Typically when using Xcode or SwiftPM, there's just one shared directory for any modules being built, so whether a dependency has been declared won't affect whether canImport will return true. Generally speaking, the compiler doesn't know at all about your declared dependencies from the package manifest today.