I am developing a .NET 7 CLI that use user inputs, files, directories, and environment variables. I want to make sure that the cmd instance's environment variables remain up-to-date even after the program has exited.
Here's what I'm trying to do:
C:\>set :: Show all environment variables
MyEnvironmentVariable=value1
C:\>MyProgram.exe
* Doing this and that *
* Refreshing environment variables *
C:\>set
MyEnvironmentVariable=value2
I've attempted a few solutions, but they didn't work. These include:
- Requesting ChatGPT to create a separate class that refreshes the environment variables
- Copying RefreshEnv.cmd from chocolatey and doing
System.Diagnostics.Process.Start("C:\\path\\to\\RefreshEnv.cmd")
System.Diagnostics.Process.Start("C:\\path\\to\\RefreshEnv.cmd").WaitForExit()
new ProcessStartInfo("cmd.exe", "C:\\path\\to\\RefreshEnv.cmd");