Add DebugHelper to make debugging easier

This commit is contained in:
Pranav K 2016-10-04 11:56:48 -07:00
Родитель 75c1a2a99d
Коммит 25a292ecfa
5 изменённых файлов: 47 добавлений и 1 удалений

Просмотреть файл

@ -0,0 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#if DEBUG
using System;
using System.Diagnostics;
using System.Linq;
namespace Microsoft.AspNetCore.Razor.Design.Internal
{
public class DebugHelper
{
public static void HandleDebugSwitch(ref string[] args)
{
if (args.Length > 0 && string.Equals("--debug", args[0], StringComparison.OrdinalIgnoreCase))
{
args = args.Skip(1).ToArray();
Console.Error.WriteLine("Waiting for debugger to attach. Press ENTER to continue");
Console.Error.WriteLine($"Process ID: {Process.GetCurrentProcess().Id}");
Console.ReadLine();
}
}
}
}
#endif

Просмотреть файл

@ -5,6 +5,7 @@ using System;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.AspNetCore.Razor.Design.Internal;
namespace Microsoft.AspNetCore.Razor.Design namespace Microsoft.AspNetCore.Razor.Design
{ {
@ -14,6 +15,9 @@ namespace Microsoft.AspNetCore.Razor.Design
public static int Main(string[] args) public static int Main(string[] args)
{ {
#if DEBUG
DebugHelper.HandleDebugSwitch(ref args);
#endif
var app = new RazorToolingApplication(ProgramType); var app = new RazorToolingApplication(ProgramType);
EnsureValidDispatchRecipient(ref args); EnsureValidDispatchRecipient(ref args);

Просмотреть файл

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
@ -86,6 +87,14 @@ namespace Microsoft.AspNetCore.Razor.Tools.Internal
dispatchArgs.Add(ProtocolOption.Value()); dispatchArgs.Add(ProtocolOption.Value());
} }
#if DEBUG
var commandLineArgs = Environment.GetCommandLineArgs();
if (commandLineArgs.Length > 1 && commandLineArgs[1] == "--debug")
{
dispatchArgs.Insert(0, commandLineArgs[1]);
}
#endif
var toolName = typeof(Design.Program).GetTypeInfo().Assembly.GetName().Name; var toolName = typeof(Design.Program).GetTypeInfo().Assembly.GetName().Name;
var dispatchCommand = DotnetToolDispatcher.CreateDispatchCommand( var dispatchCommand = DotnetToolDispatcher.CreateDispatchCommand(
dispatchArgs, dispatchArgs,
@ -99,7 +108,11 @@ namespace Microsoft.AspNetCore.Razor.Tools.Internal
using (var errorWriter = new StringWriter()) using (var errorWriter = new StringWriter())
{ {
var commandExitCode = dispatchCommand var commandExitCode = dispatchCommand
#if DEBUG
.ForwardStdErr(Console.Error)
#else
.ForwardStdErr(errorWriter) .ForwardStdErr(errorWriter)
#endif
.ForwardStdOut() .ForwardStdOut()
.Execute() .Execute()
.ExitCode; .ExitCode;

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Razor.Design; using Microsoft.AspNetCore.Razor.Design;
using Microsoft.AspNetCore.Razor.Design.Internal;
using Microsoft.AspNetCore.Razor.Tools.Internal; using Microsoft.AspNetCore.Razor.Tools.Internal;
namespace Microsoft.AspNetCore.Razor.Tools namespace Microsoft.AspNetCore.Razor.Tools
@ -10,6 +11,9 @@ namespace Microsoft.AspNetCore.Razor.Tools
{ {
public static int Main(string[] args) public static int Main(string[] args)
{ {
#if DEBUG
DebugHelper.HandleDebugSwitch(ref args);
#endif
var app = new RazorToolingApplication(typeof(Program)); var app = new RazorToolingApplication(typeof(Program));
ResolveTagHelpersCommandBase.Register<ResolveTagHelpersDispatchCommand>(app); ResolveTagHelpersCommandBase.Register<ResolveTagHelpersDispatchCommand>(app);

Просмотреть файл

@ -47,7 +47,7 @@ namespace Microsoft.AspNetCore.Razor.Tools.Test.Infrastructure
var outputWriter = new StringWriter(); var outputWriter = new StringWriter();
var exitCode = command var exitCode = command
.ForwardStdErr(outputWriter) .ForwardStdErr(Console.Error)
.ForwardStdOut(outputWriter) .ForwardStdOut(outputWriter)
.WorkingDirectory(projectDirectory) .WorkingDirectory(projectDirectory)
.Execute() .Execute()