10
10
using Microsoft . Extensions . Logging ;
11
11
using Microsoft . PowerShell . EditorServices . Services . DebugAdapter ;
12
12
using Microsoft . PowerShell . EditorServices . Services . PowerShell . Execution ;
13
- using Microsoft . PowerShell . EditorServices . Services . PowerShell . Host ;
14
13
using Microsoft . PowerShell . EditorServices . Services . PowerShell . Runspace ;
15
14
16
15
namespace Microsoft . PowerShell . EditorServices . Services . PowerShell . Debugging
@@ -54,10 +53,7 @@ public async Task<IReadOnlyList<BreakpointDetails>> SetLineBreakpointsAsync(
54
53
? $ "Enable-DscDebug -Breakpoint { hashtableString } "
55
54
: "Disable-DscDebug" ) ;
56
55
57
- await executionService . ExecutePSCommandAsync (
58
- dscCommand ,
59
- CancellationToken . None )
60
- . ConfigureAwait ( false ) ;
56
+ await executionService . ExecutePSCommandAsync ( dscCommand , CancellationToken . None ) . ConfigureAwait ( false ) ;
61
57
62
58
// Verify all the breakpoints and return them
63
59
foreach ( BreakpointDetails breakpoint in breakpoints )
@@ -77,10 +73,12 @@ public bool IsDscResourcePath(string scriptPath)
77
73
StringComparison . CurrentCultureIgnoreCase ) ) ;
78
74
}
79
75
76
+ private const string prevProgressPreferenceVariable = $ "$global:{ DebugService . PsesGlobalVariableNamePrefix } prevProgressPreference";
77
+
80
78
public static async Task < DscBreakpointCapability > GetDscCapabilityAsync (
81
79
ILogger logger ,
82
80
IRunspaceInfo currentRunspace ,
83
- PsesInternalHost psesHost )
81
+ IInternalPowerShellExecutionService executionService )
84
82
{
85
83
// DSC support is enabled only for Windows PowerShell.
86
84
if ( ( currentRunspace . PowerShellVersionDetails . Version . Major >= 6 ) &&
@@ -92,16 +90,13 @@ public static async Task<DscBreakpointCapability> GetDscCapabilityAsync(
92
90
if ( ! isDscInstalled . HasValue )
93
91
{
94
92
PSCommand psCommand = new PSCommand ( )
95
- . AddScript ( $ "$global:{ DebugService . PsesGlobalVariableNamePrefix } prevProgressPreference = $ProgressPreference")
96
- . AddScript ( "$ProgressPreference = 'SilentlyContinue'" )
97
93
. AddCommand ( @"Microsoft.PowerShell.Core\Import-Module" )
98
94
. AddParameter ( "Name" , "PSDesiredStateConfiguration" )
99
95
. AddParameter ( "PassThru" )
100
- . AddParameter ( "ErrorAction" , ActionPreference . Ignore )
101
- . AddScript ( $ "$ProgressPreference = $global:{ DebugService . PsesGlobalVariableNamePrefix } prevProgressPreference") ;
96
+ . AddParameter ( "ErrorAction" , ActionPreference . Ignore ) ;
102
97
103
98
IReadOnlyList < PSModuleInfo > dscModule =
104
- await psesHost . ExecutePSCommandAsync < PSModuleInfo > (
99
+ await executionService . ExecutePSCommandAsync < PSModuleInfo > (
105
100
psCommand ,
106
101
CancellationToken . None ,
107
102
new PowerShellExecutionOptions { ThrowOnError = false } )
@@ -113,19 +108,36 @@ await psesHost.ExecutePSCommandAsync<PSModuleInfo>(
113
108
114
109
if ( isDscInstalled . Value )
115
110
{
111
+ // Silence the progress output from Get-DscResource.
112
+ PSCommand setProgressPreferenceCommand = new PSCommand ( )
113
+ . AddScript ( $ "{ prevProgressPreferenceVariable } = $ProgressPreference")
114
+ . AddStatement ( )
115
+ . AddScript ( "$ProgressPreference = 'SilentlyContinue'" ) ;
116
+
117
+ await executionService . ExecutePSCommandAsync (
118
+ setProgressPreferenceCommand , CancellationToken . None ) . ConfigureAwait ( false ) ;
119
+
116
120
PSCommand psCommand = new PSCommand ( )
117
121
. AddCommand ( "Get-DscResource" )
118
122
. AddCommand ( "Select-Object" )
119
123
. AddParameter ( "ExpandProperty" , "ParentPath" ) ;
120
124
121
125
IReadOnlyList < string > resourcePaths =
122
- await psesHost . ExecutePSCommandAsync < string > (
126
+ await executionService . ExecutePSCommandAsync < string > (
123
127
psCommand ,
124
128
CancellationToken . None ,
125
129
new PowerShellExecutionOptions { ThrowOnError = false }
126
130
) . ConfigureAwait ( false ) ;
127
131
128
132
logger . LogTrace ( $ "DSC resources found: { resourcePaths . Count } ") ;
133
+
134
+ // Restore previous progress preference.
135
+ PSCommand restoreProgressPreferenceCommand = new PSCommand ( )
136
+ . AddScript ( $ "$ProgressPreference = { prevProgressPreferenceVariable } ") ;
137
+
138
+ await executionService . ExecutePSCommandAsync (
139
+ restoreProgressPreferenceCommand , CancellationToken . None ) . ConfigureAwait ( false ) ;
140
+
129
141
return new DscBreakpointCapability
130
142
{
131
143
dscResourceRootPaths = resourcePaths . ToArray ( )
0 commit comments