From 139cab337f116d258ad82fd22d2c0f54c307b2e9 Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Tue, 12 Sep 2023 15:28:22 -0600 Subject: [PATCH 1/4] Env variable logic for AZ PS upgrade notification --- src/Worker.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Worker.cs b/src/Worker.cs index e11b501c..ac36b9b1 100644 --- a/src/Worker.cs +++ b/src/Worker.cs @@ -79,9 +79,18 @@ public async static Task Main(string[] args) } }); + // This must be done before the first Runspace is created, to avoid the creation of a thread by the upgrade checker + SetVersionUpgradeOptOut(); + // Create the very first Runspace so the debugger has the target to attach to. // This PowerShell instance is shared by the first PowerShellManager instance created in the pool, // and the dependency manager (used to download dependent modules if needed). + string checkForUpgrade = Environment.GetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE"); + if (string.IsNullOrEmpty(checkForUpgrade)) + { + Environment.SetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE", "False"); + } + var firstPowerShellInstance = Utils.NewPwshInstance(); var pwshVersion = Utils.GetPowerShellVersion(firstPowerShellInstance); LogPowerShellVersion(pwshVersion); @@ -101,6 +110,15 @@ public async static Task Main(string[] args) await requestProcessor.ProcessRequestLoop(); } + private static void SetVersionUpgradeOptOut() + { + string checkForUpgrade = Environment.GetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE"); + if (string.IsNullOrEmpty(checkForUpgrade)) + { + Environment.SetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE", "False"); + } + } + // Warm up the PowerShell instance so that the subsequent function load and invocation requests are faster private static void WarmUpPowerShell(System.Management.Automation.PowerShell firstPowerShellInstance) { From 89ef882dedd21b0cc2ede61c3d2db8aa949d378f Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Wed, 13 Sep 2023 14:27:46 -0600 Subject: [PATCH 2/4] Update release notes --- release_notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/release_notes.md b/release_notes.md index e69de29b..c50d5055 100644 --- a/release_notes.md +++ b/release_notes.md @@ -0,0 +1 @@ +* New feature: Unless specified otherwise in app settings, the PowerShell worker will set the AZUREPS_CHECK_FOR_UPGRADE environment variable to "False" in all runspaces to opt-out of the version upgrade notification in Azure PowerShell added by that team. \ No newline at end of file From bb24e0a0eb6b28d88e467e75bf8d4d73ba47a451 Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Tue, 19 Sep 2023 15:03:24 -0600 Subject: [PATCH 3/4] Remove duplicated code --- src/Worker.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Worker.cs b/src/Worker.cs index ac36b9b1..5303e31f 100644 --- a/src/Worker.cs +++ b/src/Worker.cs @@ -85,11 +85,6 @@ public async static Task Main(string[] args) // Create the very first Runspace so the debugger has the target to attach to. // This PowerShell instance is shared by the first PowerShellManager instance created in the pool, // and the dependency manager (used to download dependent modules if needed). - string checkForUpgrade = Environment.GetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE"); - if (string.IsNullOrEmpty(checkForUpgrade)) - { - Environment.SetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE", "False"); - } var firstPowerShellInstance = Utils.NewPwshInstance(); var pwshVersion = Utils.GetPowerShellVersion(firstPowerShellInstance); From a087b6593799f11426468554349b0cd43ca2c6ed Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Thu, 21 Sep 2023 09:23:01 -0600 Subject: [PATCH 4/4] Disallow whitespace, remove release_notes --- release_notes.md | 1 - src/Worker.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/release_notes.md b/release_notes.md index c50d5055..e69de29b 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1 +0,0 @@ -* New feature: Unless specified otherwise in app settings, the PowerShell worker will set the AZUREPS_CHECK_FOR_UPGRADE environment variable to "False" in all runspaces to opt-out of the version upgrade notification in Azure PowerShell added by that team. \ No newline at end of file diff --git a/src/Worker.cs b/src/Worker.cs index 5303e31f..7764e867 100644 --- a/src/Worker.cs +++ b/src/Worker.cs @@ -108,7 +108,7 @@ public async static Task Main(string[] args) private static void SetVersionUpgradeOptOut() { string checkForUpgrade = Environment.GetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE"); - if (string.IsNullOrEmpty(checkForUpgrade)) + if (string.IsNullOrWhiteSpace(checkForUpgrade)) { Environment.SetEnvironmentVariable("AZUREPS_CHECK_FOR_UPGRADE", "False"); }