Xcode 14.1 - Could not generate PIF because the workspace has not finished loading

Reaching out to Apple & developer community to get help regarding an issue seen in Xcode 14.1. We have a workspace which contains multiple .xcodeproj files and also couple of Swift package sources. When I open the workspace and try to build a scheme using Xcode 14.1, I don't see any issue. However, using xcodebuild command throws this issue in CI

xcodebuild: error: Failed to build project MyProject with scheme MyProject.
Reason: internal error: could not generate PIF because the workspace has not finished loading or is still waiting for package resolution

Note that building MyProject scheme was consistently failing with the above mentioned error in CI. After changing the derived data path, the behaviour is flaky. ie, the target fails to build sometimes (with the above mentioned error) and succeeds most of the time.

I referred this post and incorporated the suggestion but it didn't resolve the issue.

rm -rf ~/Library/Caches/org.swift.swiftpm
rm -rf ~/Library/org.swift.swiftpm 

In order to ensure that the SPM cache is not causing this issue, I also tried clearing the SPM cache using the above statements before building my scheme. Even this didn't help resolve the issue.

If anyone knows a fix or a workaround to resolve this issue, kindly share.

getting same issue for test cases and luck ??

Do we know any solution yet? I am also facing the same issue, i.e  I have a workspace which contains multiple .xcodeproj files, it throws the issue in CI saying- error: Build service could not create build operation: internal error: could not generate PIF because the workspace has not finished loading or is still waiting for package resolution[0m

Xcode 14.1 - Could not generate PIF because the workspace has not finished loading
 
 
Q