Skip to content

Commit 0d33d7a

Browse files
committed
Release build was broken because of an #if DEBUG for System.Diagnostics
1 parent 4e73bf3 commit 0d33d7a

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
using SMA = System.Management.Automation;
1111
using System.Management.Automation.Runspaces;
1212
using Microsoft.PowerShell.EditorServices.Hosting;
13+
using System.Diagnostics;
1314
using System.Globalization;
1415

1516
#if DEBUG
16-
using System.Diagnostics;
1717
using System.Threading;
1818
using Debugger = System.Diagnostics.Debugger;
1919
#endif
@@ -23,7 +23,6 @@ namespace Microsoft.PowerShell.EditorServices.Commands
2323
/// <summary>
2424
/// The Start-EditorServices command, the conventional entrypoint for PowerShell Editor Services.
2525
/// </summary>
26-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "Cmdlet parameters can be arrays")]
2726
[Cmdlet(VerbsLifecycle.Start, "EditorServices", DefaultParameterSetName = "NamedPipe")]
2827
public sealed class StartEditorServicesCommand : PSCmdlet
2928
{
@@ -204,7 +203,7 @@ protected override void BeginProcessing()
204203
{
205204
// NOTE: Ignore the suggestion to use Environment.ProcessId as it doesn't work for
206205
// .NET 4.6.2 (for Windows PowerShell), and this won't be caught in CI.
207-
Console.WriteLine($"Waiting for debugger to attach, PID: {Process.GetCurrentProcess().Id}");
206+
Console.WriteLine($"Waiting for debugger to attach, PID: {s_currentPID}");
208207
while (!Debugger.IsAttached)
209208
{
210209
Thread.Sleep(1000);

src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Diagnostics;
56
using System.IO;
67
using Microsoft.Extensions.DependencyInjection;
78
using Microsoft.Extensions.Logging;
@@ -13,7 +14,6 @@
1314
using Microsoft.PowerShell.EditorServices.Services.Extension;
1415

1516
#if DEBUG
16-
using System.Diagnostics;
1717
using Serilog.Debugging;
1818
#endif
1919

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/LaunchAndAttachHandler.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ internal record PsesAttachRequestArguments : AttachRequestArguments
8787

8888
internal class LaunchAndAttachHandler : ILaunchHandler<PsesLaunchRequestArguments>, IAttachHandler<PsesAttachRequestArguments>, IOnDebugAdapterServerStarted
8989
{
90-
private static readonly int currentProcessId = System.Diagnostics.Process.GetCurrentProcess().Id;
90+
private static readonly int s_currentPID = System.Diagnostics.Process.GetCurrentProcess().Id;
9191
private static readonly Version s_minVersionForCustomPipeName = new(6, 2);
9292
private readonly ILogger<LaunchAndAttachHandler> _logger;
9393
private readonly BreakpointService _breakpointService;
@@ -275,7 +275,7 @@ void RunspaceChangedHandler(object s, RunspaceChangedEventArgs _)
275275

276276
if (processIdIsSet)
277277
{
278-
if (request.ProcessId == currentProcessId)
278+
if (request.ProcessId == s_currentPID)
279279
{
280280
throw new RpcErrorException(0, null, $"Attaching to the Extension Terminal is not supported!");
281281
}

src/PowerShellEditorServices/Services/PowerShell/Handlers/PSHostProcessAndRunspaceHandlers.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal class PSHostProcessAndRunspaceHandlers : IGetPSHostProcessesHandler, IG
1919
private readonly ILogger<PSHostProcessAndRunspaceHandlers> _logger;
2020
private readonly IInternalPowerShellExecutionService _executionService;
2121
private readonly IRunspaceContext _runspaceContext;
22-
private static readonly int currentProcessId = System.Diagnostics.Process.GetCurrentProcess().Id;
22+
private static readonly int s_currentPID = System.Diagnostics.Process.GetCurrentProcess().Id;
2323

2424
public PSHostProcessAndRunspaceHandlers(
2525
ILoggerFactory factory,
@@ -50,7 +50,7 @@ public async Task<PSHostProcessResponse[]> Handle(GetPSHostProcessesParams reque
5050

5151
// NOTE: We do not currently support attaching to ourself in this manner, so we
5252
// exclude our process. When we maybe eventually do, we should name it.
53-
if (response.ProcessId == currentProcessId)
53+
if (response.ProcessId == s_currentPID)
5454
{
5555
continue;
5656
}
@@ -63,7 +63,7 @@ public async Task<PSHostProcessResponse[]> Handle(GetPSHostProcessesParams reque
6363

6464
public async Task<RunspaceResponse[]> Handle(GetRunspaceParams request, CancellationToken cancellationToken)
6565
{
66-
if (request.ProcessId == currentProcessId)
66+
if (request.ProcessId == s_currentPID)
6767
{
6868
throw new RpcErrorException(0, null, $"Attaching to the Extension Terminal is not supported!");
6969
}

0 commit comments

Comments
 (0)