AzureCliCredentials & PATH on MAC
Hey,
when I try to use a AzureCliCredential to authenticate against Azure services, LINQPad uses a path, where my azure cli is not included, when installed via home-brew.
Quick fix is using this snippet within the query at the beginning:
Environment.SetEnvironmentVariable("PATH", $"/opt/homebrew/bin:/opt/homebrew/sbin:{Environment.GetEnvironmentVariable("PATH")}");
How can I solve that?
Answers
-
You could create a class in My Extensions to do this:
public static class MyUtil { public static void Azure() => Environment.SetEnvironmentVariable("PATH", $"/opt/homebrew/bin:/opt/homebrew/sbin:{Environment.GetEnvironmentVariable("PATH")}"); }Updating your path globally via the OS, in a way that works reliably with both the command-line and applications is difficult (or even impossible?) on macOS.
-
One other approach that would feel a little more natural and worth mentioning is to create a script that you would load in. Treat it like a "source include." You could add that setup in your
OnInit()method for the script.Azure.linq:
void OnInit() { // this runs once at start when #loaded in another script Environment.SetEnvironmentVariable("PATH", $"/opt/homebrew/bin:/opt/homebrew/sbin:{Environment.GetEnvironmentVariable("PATH")}"); }Then all you would need to do is
#loadit in your scripts that utilizes it.#load "Azure" void Main() { // it should work as expected now }
