Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap import of DSC module with ProgressPreference = SilentlyContinue #2068

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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