Xcode not follows system proxy settings to resolve SwiftPM dependencies

I did a little experiment. I opened up a shell, set an environment variable, then used the 'open' command:

open -a Xcode.app

I a created a test command line app, and added a run-script phase that simply used 'printenv' (tcsh shell, there is an equivalent for bash, zsh, may even be printenv). That environment variable was in the list. I then closed out Xcode, and re-started it by double clicking. Opened the same project, cleaned the build folder, and re-built the project. Looking at the list, the environment value was not there. So, you might get away with using the "open Xcode.app" in a shell to get your proxies to work.

I think Xcode uses whatever environment has been setup when it's invoked. If you open it by double clicking, it's running the in the WindowServer process, which inherits the environment from launchd, the top-most daemon on MacOS. That's a pretty minimal environment. There are ways you can add environment variables to the launchd environment, but, it is more esoteric than it used to be. Opening Xcode using the 'open' command in the shell inherits the environment of that shell instance.

4 Likes