Saturday 18 June 2022

Set Environment Variable for .NET Core Running in WSL2 Ubuntu 20.04 Distro

Testing .NET Core applications with environment varaibles as dependency, on Linux using WSL2 and Ubuntu distro, requires you to set environemnt varaibles in WSL2 distro. For settiing up environement variable in your WSL2 distro you can use the ~/.profile file.

In your WSL terminal or in VS Code using terminal of your ubuntu distro, run below command to edit the ~/.profile file.

sudo vim ~/.profile

At the end of the file content add your environment variables in following syntax.

export MYAPP_CONFIG_PATH="/mnt/c/myconfig/my-config.json"

export MYAPP_EnvName="Demo"

Then save the file with ESC+:wq!  (wrting to file with vim).

If you want check if the update to file is saved, you can run cat ~/.profile


Once you have the  ~/.profile updated with your envronement variable your .NET core applications can access them while running in your Ubuntu WSL2 distro.

No comments:

Popular Posts