Timothy Carter
Timothy Carter

Reputation: 15785

Refresh environment variables for open VS solution

Using visual studio 2008, I had a solution open and realized I need to install another program that the project I was working on used. I did this with visual studio open and attempted to debug the program, however the environment variables added by the program I installed were not visible. I could not get them to refresh until I exited VS and reloaded the solution. Is there a way to get visual studio to "refresh" its environment variable list without exiting and reloading the solution?

As an additional note, I did use process explorer to look at the environment variables for the application and could confirm that it was not aware of the environment variable I needed.

Upvotes: 45

Views: 22964

Answers (3)

Tore Aurstad
Tore Aurstad

Reputation: 3826

This is a very old question, but it is still something VS users probably want to do without closing down the entire VS process.

You can get the environment variables without restarting VS 2022 process if you open up a terminal and with the help of this Chocolatey command:

refreshenv

Obviously, this requires that you have installed Chocolatey on your system.

Please note that if you have added environment variable as a system variable, set also the EnvironmentVariableTarget to Machine. Example :

string uri = Environment.GetEnvironmentVariable("AZURE_COGNITIVE_SERVICE_ENDPOINT", EnvironmentVariableTarget.Machine);

Upvotes: 1

Ade Miller
Ade Miller

Reputation: 13733

I don't think there's any way round this. You have to restart the VS process so it can pick up the changes to the environment.

Upvotes: 2

Nick Meyer
Nick Meyer

Reputation: 40352

Nope. Environment variable changes on Windows only take effect for new processes. You'll have to exit Visual Studio and restart it.

Upvotes: 54

Related Questions