Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Commit 25a292e

Browse files
committed
Add DebugHelper to make debugging easier
1 parent 75c1a2a commit 25a292e

5 files changed

Lines changed: 47 additions & 1 deletion

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
#if DEBUG
5+
using System;
6+
using System.Diagnostics;
7+
using System.Linq;
8+
9+
namespace Microsoft.AspNetCore.Razor.Design.Internal
10+
{
11+
public class DebugHelper
12+
{
13+
public static void HandleDebugSwitch(ref string[] args)
14+
{
15+
if (args.Length > 0 && string.Equals("--debug", args[0], StringComparison.OrdinalIgnoreCase))
16+
{
17+
args = args.Skip(1).ToArray();
18+
Console.Error.WriteLine("Waiting for debugger to attach. Press ENTER to continue");
19+
Console.Error.WriteLine($"Process ID: {Process.GetCurrentProcess().Id}");
20+
Console.ReadLine();
21+
}
22+
}
23+
}
24+
}
25+
#endif

src/Microsoft.AspNetCore.Razor.Design/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Globalization;
66
using System.Linq;
77
using System.Reflection;
8+
using Microsoft.AspNetCore.Razor.Design.Internal;
89

910
namespace Microsoft.AspNetCore.Razor.Design
1011
{
@@ -14,6 +15,9 @@ public class Program
1415

1516
public static int Main(string[] args)
1617
{
18+
#if DEBUG
19+
DebugHelper.HandleDebugSwitch(ref args);
20+
#endif
1721
var app = new RazorToolingApplication(ProgramType);
1822

1923
EnsureValidDispatchRecipient(ref args);

src/Microsoft.AspNetCore.Razor.Tools/Internal/ResolveTagHelpersDispatchCommand.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Globalization;
67
using System.IO;
@@ -86,6 +87,14 @@ protected override int OnExecute()
8687
dispatchArgs.Add(ProtocolOption.Value());
8788
}
8889

90+
#if DEBUG
91+
var commandLineArgs = Environment.GetCommandLineArgs();
92+
if (commandLineArgs.Length > 1 && commandLineArgs[1] == "--debug")
93+
{
94+
dispatchArgs.Insert(0, commandLineArgs[1]);
95+
}
96+
#endif
97+
8998
var toolName = typeof(Design.Program).GetTypeInfo().Assembly.GetName().Name;
9099
var dispatchCommand = DotnetToolDispatcher.CreateDispatchCommand(
91100
dispatchArgs,
@@ -99,7 +108,11 @@ protected override int OnExecute()
99108
using (var errorWriter = new StringWriter())
100109
{
101110
var commandExitCode = dispatchCommand
111+
#if DEBUG
112+
.ForwardStdErr(Console.Error)
113+
#else
102114
.ForwardStdErr(errorWriter)
115+
#endif
103116
.ForwardStdOut()
104117
.Execute()
105118
.ExitCode;

src/Microsoft.AspNetCore.Razor.Tools/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using Microsoft.AspNetCore.Razor.Design;
5+
using Microsoft.AspNetCore.Razor.Design.Internal;
56
using Microsoft.AspNetCore.Razor.Tools.Internal;
67

78
namespace Microsoft.AspNetCore.Razor.Tools
@@ -10,6 +11,9 @@ public class Program
1011
{
1112
public static int Main(string[] args)
1213
{
14+
#if DEBUG
15+
DebugHelper.HandleDebugSwitch(ref args);
16+
#endif
1317
var app = new RazorToolingApplication(typeof(Program));
1418

1519
ResolveTagHelpersCommandBase.Register<ResolveTagHelpersDispatchCommand>(app);

test/Microsoft.AspNetCore.Razor.Tools.Test/Infrastructure/ToolTestFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public StringBuilder DotNet(string projectDirectory, string commandName, params
4747
var outputWriter = new StringWriter();
4848

4949
var exitCode = command
50-
.ForwardStdErr(outputWriter)
50+
.ForwardStdErr(Console.Error)
5151
.ForwardStdOut(outputWriter)
5252
.WorkingDirectory(projectDirectory)
5353
.Execute()

0 commit comments

Comments
 (0)