0

The next code in Windows runs as expected and prints Favorite Song = Hardwell, Spaceman. But if I run it on Linux, it returns Favorite Song = is null. It also doesn't work with EnvironmentVariableTarget.Machine. (console application net5)

What am I doing wrong? Why is Linux so weird?

class Program
{
    static void Main(string[] args)
    {
        Environment.SetEnvironmentVariable("FavoriteSong", "Hardwell, Spaceman ", EnvironmentVariableTarget.User);
        // test
        var song = Environment.GetEnvironmentVariable("FavoriteSong", EnvironmentVariableTarget.User);

        Console.WriteLine("Favorite Song = {0}", song ?? "is null");
    }
}
  • Did you read the [docs on `EnvironmentVariableTarget`](https://learn.microsoft.com/en-us/dotnet/api/system.environmentvariabletarget?view=net-5.0) ? One could more rightfully ask, "why is Windows so weird?". – jwdonahue Jul 18 '21 at 23:07
  • OK. Without EnvironmentVariableTarget, works. TXS – Alexandra Danith Ansley Jul 19 '21 at 00:36
  • 1
    I will make a clarification on the question, and that generated my confusion. About this document: https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-dotnet#configure-your-storage-connection-string Should be: ```basch setx AZURE_STORAGE_CONNECTION_STRING "" /m ``` To be effective it works on Windows and Linux, since for Linux they say bach use export. About this suggestion: c# - How to set a global environment variable in .NET Core (user-wide or system-wide) - Stack Overflow, does not clarify the doubt. – Alexandra Danith Ansley Jul 19 '21 at 01:14

0 Answers0