Skip to content

Commit

Permalink
Wrap import of DSC module with ProgressPreference = SilentlyContinue
Browse files Browse the repository at this point in the history
And set it back afterwards. Since it has `ErrorAction = Ignore` it
should always get set back correctly. This prevents the progress pane
from getting stuck in certain circumstances.
  • Loading branch information
andyleejordan committed Sep 19, 2023
1 parent a6b4a92 commit 4974016
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class DebugService
{
#region Fields

private const string PsesGlobalVariableNamePrefix = "__psEditorServices_";
internal const string PsesGlobalVariableNamePrefix = "__psEditorServices_";
private const string TemporaryScriptFileName = "Script Listing.ps1";

private readonly ILogger _logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ internal static class BreakpointApiUtils
{
#region Private Static Fields

private const string s_psesGlobalVariableNamePrefix = "__psEditorServices_";

private static readonly Lazy<Func<Debugger, string, int, int, ScriptBlock, int?, LineBreakpoint>> s_setLineBreakpointLazy;

private static readonly Lazy<Func<Debugger, string, ScriptBlock, string, int?, CommandBreakpoint>> s_setCommandBreakpointLazy;
Expand Down Expand Up @@ -199,7 +197,7 @@ public static ScriptBlock GetBreakpointActionScriptBlock(string condition, strin
int incrementResult = Interlocked.Increment(ref breakpointHitCounter);

string globalHitCountVarName =
$"$global:{s_psesGlobalVariableNamePrefix}BreakHitCounter_{incrementResult}";
$"$global:{DebugService.PsesGlobalVariableNamePrefix}BreakHitCounter_{incrementResult}";

builder.Insert(0, $"if (++{globalHitCountVarName} -eq {parsedHitCount}) {{ ")
.Append(" }");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ public static async Task<DscBreakpointCapability> GetDscCapabilityAsync(
if (!isDscInstalled.HasValue)
{
PSCommand psCommand = new PSCommand()
.AddScript($"$global:{DebugService.PsesGlobalVariableNamePrefix}prevProgressPreference = $ProgressPreference")
.AddScript("$ProgressPreference = 'SilentlyContinue'")
.AddCommand(@"Microsoft.PowerShell.Core\Import-Module")
.AddParameter("-Name", "PSDesiredStateConfiguration")
.AddParameter("Name", "PSDesiredStateConfiguration")
.AddParameter("PassThru")
.AddParameter("ErrorAction", ActionPreference.Ignore);
.AddParameter("ErrorAction", ActionPreference.Ignore)
.AddScript($"$ProgressPreference = $global:{DebugService.PsesGlobalVariableNamePrefix}prevProgressPreference");

IReadOnlyList<PSModuleInfo> dscModule =
await psesHost.ExecutePSCommandAsync<PSModuleInfo>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static void SetCorrectExecutionPolicy(this PowerShell pwsh, ILogger logge
// Calling the cmdlet is the simplest way to do that
IReadOnlyList<PSObject> policies = pwsh
.AddCommand(@"Microsoft.PowerShell.Security\Get-ExecutionPolicy")
.AddParameter("-List")
.AddParameter("List")
.InvokeAndClear<PSObject>();

// The policies come out in the following order:
Expand Down Expand Up @@ -223,7 +223,7 @@ public static void LoadProfiles(this PowerShell pwsh, ProfilePathInfo profilePat
public static void ImportModule(this PowerShell pwsh, string moduleNameOrPath)
{
pwsh.AddCommand(@"Microsoft.PowerShell.Core\Import-Module")
.AddParameter("-Name", moduleNameOrPath)
.AddParameter("Name", moduleNameOrPath)
.InvokeAndClear();
}

Expand Down

0 comments on commit 4974016

Please sign in to comment.