Search code examples
c#visual-studio.net-coremonovisual-studio-mac

ConfigurationBuilder().AddEnvironmentVariables() not working on Mac


Having this issue with visual studio for Mac - Can't load my configured environment variables.

If i run the app from a Terminal it works, but it doesn't if i run it from Visual Studio for Mac.

I added my variables to:

  1. .bashrc
  2. .bash_profile

I am using Visual Studio v8.7.8

(Yes, i tried restarting visual studio, even restarting the computer).

Any help is useful.

Thanks.

--EDIT--

I created the same post in Microsoft's dev community. Hopefully they fix this on the future. Stick to running VS from a Terminal for now.


Solution

  • So, unfortunately Visual Studio for Mac does not support using environment variables defined via bash or zsh (yet?...).

    There is a hacky workaround by launching VS from a Terminal

    /Applications/Visual\ Studio.app/Contents/MacOS/VisualStudio &
    

    Launching it this way will allow VS to access user configured variables.

    To make it easier to remember, an alias can be created by:

    alias vs='/Applications/Visual\ Studio.app/Contents/MacOS/VisualStudio &'
    

    Just remember to add this line to .bash_profile and .bashrc

    Here is a Medium article on how to edit these files.

    Here is a Blog post describing the VS issue.