IOS Notifications: Embedded binary's bundle identifier is not prefixed with the parent app's bundle identifier

I have an iOS app, which uses Notification Service Extension (NSE) for its functioning. When I build the app, I get the following error:

error: Embedded binary's bundle identifier is not prefixed with the parent app's bundle identifier.

Embedded Binary Bundle Identifier:  (null)
Parent App Bundle Identifier: com.example.sample

This error occurs when NSE doesn't have the app's bundle identifier prefixed to it (Reference post).

In my case, the bundle ID of the app is com.example.sample and the bundle ID of the extension, com.example.sample.NSESample (checked these values in Project -> Target -> Signing & capabilities -> bundle identifier label). I believe this is as expected. I don't understand this error now, which says the embedded bundle identifier is null. I cleaned and built the app again..... same error.

According to this stackoverflow post, you have to enable 'Copy only when installing'. When I tried, it worked. I don't know what this setting means and how this solves the issue. I'm unable to find any documentation reg this setting. Idk if this is even a valid solution, because the error says 'Embedded Binary Bundle Identifier' is null.

Why is the embedded bundle identifier null (despite the Xcode interface showing a valid bundle ID)? How can I solve this?