diff --git a/Microsoft.DotNet.Cli.sln b/Microsoft.DotNet.Cli.sln index 7944602e0..cb91c90cf 100644 --- a/Microsoft.DotNet.Cli.sln +++ b/Microsoft.DotNet.Cli.sln @@ -39,13 +39,13 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Tools.Init EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Tools.Compiler.Native", "src\Microsoft.DotNet.Tools.Compiler.Native\Microsoft.DotNet.Tools.Compiler.Native.xproj", "{172485DD-B94E-4F3E-851E-CF23908FF960}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ALL_BUILD", "src\corehost\cmake\win7-x64\ALL_BUILD.vcxproj", "{7DFC6663-5AF1-4307-AAD7-B056011EF6F0}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ALL_BUILD", "src\corehost\cmake\win7-x64\ALL_BUILD.vcxproj", "{86A16EC3-EC30-391A-A411-9E7EF1357A0A}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "corehost", "src\corehost\cmake\win7-x64\corehost.vcxproj", "{1187A81C-B59E-4B0B-A0A0-ED55D8E39A9D}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "corehost", "src\corehost\cmake\win7-x64\corehost.vcxproj", "{D22D1279-24FF-3F01-9ADB-9F23CA8AD062}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZERO_CHECK", "src\corehost\cmake\win7-x64\ZERO_CHECK.vcxproj", "{C3B057EE-D6C1-4D16-9E1F-D0EED4181D13}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZERO_CHECK", "src\corehost\cmake\win7-x64\ZERO_CHECK.vcxproj", "{AB25E68A-8581-30C1-B19C-61FCADE4774C}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Tools.Pack", "src\Microsoft.DotNet.Tools.Pack\Microsoft.DotNet.Tools.Pack.xproj", "{3E196F0D-ACEA-433D-8D07-5F8A44517C28}" +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Tools.Pack", "src\Microsoft.DotNet.Tools.Pack\Microsoft.DotNet.Tools.Pack.xproj", "{0F480791-4BA0-44E3-8CC4-C71656664175}" EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.ProjectModel.Workspaces", "src\Microsoft.DotNet.ProjectModel.Workspaces\Microsoft.DotNet.ProjectModel.Workspaces.xproj", "{BD7833F8-3209-4682-BF75-B4BCA883E279}" EndProject @@ -271,58 +271,58 @@ Global {172485DD-B94E-4F3E-851E-CF23908FF960}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU {172485DD-B94E-4F3E-851E-CF23908FF960}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU {172485DD-B94E-4F3E-851E-CF23908FF960}.RelWithDebInfo|x64.Build.0 = Release|Any CPU - {7DFC6663-5AF1-4307-AAD7-B056011EF6F0}.Debug|Any CPU.ActiveCfg = Debug|x64 - {7DFC6663-5AF1-4307-AAD7-B056011EF6F0}.Debug|x64.ActiveCfg = Debug|x64 - {7DFC6663-5AF1-4307-AAD7-B056011EF6F0}.Debug|x64.Build.0 = Debug|x64 - {7DFC6663-5AF1-4307-AAD7-B056011EF6F0}.MinSizeRel|Any CPU.ActiveCfg = MinSizeRel|x64 - {7DFC6663-5AF1-4307-AAD7-B056011EF6F0}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 - {7DFC6663-5AF1-4307-AAD7-B056011EF6F0}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 - {7DFC6663-5AF1-4307-AAD7-B056011EF6F0}.Release|Any CPU.ActiveCfg = Release|x64 - {7DFC6663-5AF1-4307-AAD7-B056011EF6F0}.Release|x64.ActiveCfg = Release|x64 - {7DFC6663-5AF1-4307-AAD7-B056011EF6F0}.Release|x64.Build.0 = Release|x64 - {7DFC6663-5AF1-4307-AAD7-B056011EF6F0}.RelWithDebInfo|Any CPU.ActiveCfg = RelWithDebInfo|x64 - {7DFC6663-5AF1-4307-AAD7-B056011EF6F0}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 - {7DFC6663-5AF1-4307-AAD7-B056011EF6F0}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 - {1187A81C-B59E-4B0B-A0A0-ED55D8E39A9D}.Debug|Any CPU.ActiveCfg = Debug|x64 - {1187A81C-B59E-4B0B-A0A0-ED55D8E39A9D}.Debug|x64.ActiveCfg = Debug|x64 - {1187A81C-B59E-4B0B-A0A0-ED55D8E39A9D}.Debug|x64.Build.0 = Debug|x64 - {1187A81C-B59E-4B0B-A0A0-ED55D8E39A9D}.MinSizeRel|Any CPU.ActiveCfg = MinSizeRel|x64 - {1187A81C-B59E-4B0B-A0A0-ED55D8E39A9D}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 - {1187A81C-B59E-4B0B-A0A0-ED55D8E39A9D}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 - {1187A81C-B59E-4B0B-A0A0-ED55D8E39A9D}.Release|Any CPU.ActiveCfg = Release|x64 - {1187A81C-B59E-4B0B-A0A0-ED55D8E39A9D}.Release|x64.ActiveCfg = Release|x64 - {1187A81C-B59E-4B0B-A0A0-ED55D8E39A9D}.Release|x64.Build.0 = Release|x64 - {1187A81C-B59E-4B0B-A0A0-ED55D8E39A9D}.RelWithDebInfo|Any CPU.ActiveCfg = RelWithDebInfo|x64 - {1187A81C-B59E-4B0B-A0A0-ED55D8E39A9D}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 - {1187A81C-B59E-4B0B-A0A0-ED55D8E39A9D}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 - {C3B057EE-D6C1-4D16-9E1F-D0EED4181D13}.Debug|Any CPU.ActiveCfg = Debug|x64 - {C3B057EE-D6C1-4D16-9E1F-D0EED4181D13}.Debug|x64.ActiveCfg = Debug|x64 - {C3B057EE-D6C1-4D16-9E1F-D0EED4181D13}.Debug|x64.Build.0 = Debug|x64 - {C3B057EE-D6C1-4D16-9E1F-D0EED4181D13}.MinSizeRel|Any CPU.ActiveCfg = MinSizeRel|x64 - {C3B057EE-D6C1-4D16-9E1F-D0EED4181D13}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 - {C3B057EE-D6C1-4D16-9E1F-D0EED4181D13}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 - {C3B057EE-D6C1-4D16-9E1F-D0EED4181D13}.Release|Any CPU.ActiveCfg = Release|x64 - {C3B057EE-D6C1-4D16-9E1F-D0EED4181D13}.Release|x64.ActiveCfg = Release|x64 - {C3B057EE-D6C1-4D16-9E1F-D0EED4181D13}.Release|x64.Build.0 = Release|x64 - {C3B057EE-D6C1-4D16-9E1F-D0EED4181D13}.RelWithDebInfo|Any CPU.ActiveCfg = RelWithDebInfo|x64 - {C3B057EE-D6C1-4D16-9E1F-D0EED4181D13}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 - {C3B057EE-D6C1-4D16-9E1F-D0EED4181D13}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.Debug|x64.ActiveCfg = Debug|Any CPU - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.Debug|x64.Build.0 = Debug|Any CPU - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.MinSizeRel|x64.Build.0 = Debug|Any CPU - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.Release|Any CPU.Build.0 = Release|Any CPU - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.Release|x64.ActiveCfg = Release|Any CPU - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.Release|x64.Build.0 = Release|Any CPU - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU - {3E196F0D-ACEA-433D-8D07-5F8A44517C28}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {86A16EC3-EC30-391A-A411-9E7EF1357A0A}.Debug|Any CPU.ActiveCfg = Debug|x64 + {86A16EC3-EC30-391A-A411-9E7EF1357A0A}.Debug|x64.ActiveCfg = Debug|x64 + {86A16EC3-EC30-391A-A411-9E7EF1357A0A}.Debug|x64.Build.0 = Debug|x64 + {86A16EC3-EC30-391A-A411-9E7EF1357A0A}.MinSizeRel|Any CPU.ActiveCfg = MinSizeRel|x64 + {86A16EC3-EC30-391A-A411-9E7EF1357A0A}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 + {86A16EC3-EC30-391A-A411-9E7EF1357A0A}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 + {86A16EC3-EC30-391A-A411-9E7EF1357A0A}.Release|Any CPU.ActiveCfg = Release|x64 + {86A16EC3-EC30-391A-A411-9E7EF1357A0A}.Release|x64.ActiveCfg = Release|x64 + {86A16EC3-EC30-391A-A411-9E7EF1357A0A}.Release|x64.Build.0 = Release|x64 + {86A16EC3-EC30-391A-A411-9E7EF1357A0A}.RelWithDebInfo|Any CPU.ActiveCfg = RelWithDebInfo|x64 + {86A16EC3-EC30-391A-A411-9E7EF1357A0A}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 + {86A16EC3-EC30-391A-A411-9E7EF1357A0A}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 + {D22D1279-24FF-3F01-9ADB-9F23CA8AD062}.Debug|Any CPU.ActiveCfg = Debug|x64 + {D22D1279-24FF-3F01-9ADB-9F23CA8AD062}.Debug|x64.ActiveCfg = Debug|x64 + {D22D1279-24FF-3F01-9ADB-9F23CA8AD062}.Debug|x64.Build.0 = Debug|x64 + {D22D1279-24FF-3F01-9ADB-9F23CA8AD062}.MinSizeRel|Any CPU.ActiveCfg = MinSizeRel|x64 + {D22D1279-24FF-3F01-9ADB-9F23CA8AD062}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 + {D22D1279-24FF-3F01-9ADB-9F23CA8AD062}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 + {D22D1279-24FF-3F01-9ADB-9F23CA8AD062}.Release|Any CPU.ActiveCfg = Release|x64 + {D22D1279-24FF-3F01-9ADB-9F23CA8AD062}.Release|x64.ActiveCfg = Release|x64 + {D22D1279-24FF-3F01-9ADB-9F23CA8AD062}.Release|x64.Build.0 = Release|x64 + {D22D1279-24FF-3F01-9ADB-9F23CA8AD062}.RelWithDebInfo|Any CPU.ActiveCfg = RelWithDebInfo|x64 + {D22D1279-24FF-3F01-9ADB-9F23CA8AD062}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 + {D22D1279-24FF-3F01-9ADB-9F23CA8AD062}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 + {AB25E68A-8581-30C1-B19C-61FCADE4774C}.Debug|Any CPU.ActiveCfg = Debug|x64 + {AB25E68A-8581-30C1-B19C-61FCADE4774C}.Debug|x64.ActiveCfg = Debug|x64 + {AB25E68A-8581-30C1-B19C-61FCADE4774C}.Debug|x64.Build.0 = Debug|x64 + {AB25E68A-8581-30C1-B19C-61FCADE4774C}.MinSizeRel|Any CPU.ActiveCfg = MinSizeRel|x64 + {AB25E68A-8581-30C1-B19C-61FCADE4774C}.MinSizeRel|x64.ActiveCfg = MinSizeRel|x64 + {AB25E68A-8581-30C1-B19C-61FCADE4774C}.MinSizeRel|x64.Build.0 = MinSizeRel|x64 + {AB25E68A-8581-30C1-B19C-61FCADE4774C}.Release|Any CPU.ActiveCfg = Release|x64 + {AB25E68A-8581-30C1-B19C-61FCADE4774C}.Release|x64.ActiveCfg = Release|x64 + {AB25E68A-8581-30C1-B19C-61FCADE4774C}.Release|x64.Build.0 = Release|x64 + {AB25E68A-8581-30C1-B19C-61FCADE4774C}.RelWithDebInfo|Any CPU.ActiveCfg = RelWithDebInfo|x64 + {AB25E68A-8581-30C1-B19C-61FCADE4774C}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 + {AB25E68A-8581-30C1-B19C-61FCADE4774C}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 + {0F480791-4BA0-44E3-8CC4-C71656664175}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0F480791-4BA0-44E3-8CC4-C71656664175}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0F480791-4BA0-44E3-8CC4-C71656664175}.Debug|x64.ActiveCfg = Debug|Any CPU + {0F480791-4BA0-44E3-8CC4-C71656664175}.Debug|x64.Build.0 = Debug|Any CPU + {0F480791-4BA0-44E3-8CC4-C71656664175}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {0F480791-4BA0-44E3-8CC4-C71656664175}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {0F480791-4BA0-44E3-8CC4-C71656664175}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {0F480791-4BA0-44E3-8CC4-C71656664175}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {0F480791-4BA0-44E3-8CC4-C71656664175}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0F480791-4BA0-44E3-8CC4-C71656664175}.Release|Any CPU.Build.0 = Release|Any CPU + {0F480791-4BA0-44E3-8CC4-C71656664175}.Release|x64.ActiveCfg = Release|Any CPU + {0F480791-4BA0-44E3-8CC4-C71656664175}.Release|x64.Build.0 = Release|Any CPU + {0F480791-4BA0-44E3-8CC4-C71656664175}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {0F480791-4BA0-44E3-8CC4-C71656664175}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {0F480791-4BA0-44E3-8CC4-C71656664175}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {0F480791-4BA0-44E3-8CC4-C71656664175}.RelWithDebInfo|x64.Build.0 = Release|Any CPU {BD7833F8-3209-4682-BF75-B4BCA883E279}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {BD7833F8-3209-4682-BF75-B4BCA883E279}.Debug|Any CPU.Build.0 = Debug|Any CPU {BD7833F8-3209-4682-BF75-B4BCA883E279}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -374,10 +374,10 @@ Global {A16958E1-24C7-4F1E-B317-204AD91625DD} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} {BC765FBF-AD7A-4A99-9902-5540C5A74181} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} {172485DD-B94E-4F3E-851E-CF23908FF960} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} - {7DFC6663-5AF1-4307-AAD7-B056011EF6F0} = {C0CA389D-A35E-4082-BC05-598C9D6301BC} - {1187A81C-B59E-4B0B-A0A0-ED55D8E39A9D} = {C0CA389D-A35E-4082-BC05-598C9D6301BC} - {C3B057EE-D6C1-4D16-9E1F-D0EED4181D13} = {C0CA389D-A35E-4082-BC05-598C9D6301BC} - {3E196F0D-ACEA-433D-8D07-5F8A44517C28} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} + {86A16EC3-EC30-391A-A411-9E7EF1357A0A} = {C0CA389D-A35E-4082-BC05-598C9D6301BC} + {D22D1279-24FF-3F01-9ADB-9F23CA8AD062} = {C0CA389D-A35E-4082-BC05-598C9D6301BC} + {AB25E68A-8581-30C1-B19C-61FCADE4774C} = {C0CA389D-A35E-4082-BC05-598C9D6301BC} + {0F480791-4BA0-44E3-8CC4-C71656664175} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} {BD7833F8-3209-4682-BF75-B4BCA883E279} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} {DB29F219-DC92-4AF7-A2EE-E89FFBB3F5F0} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} EndGlobalSection diff --git a/NuGet.Config b/NuGet.Config index 487061fcf..e1669ca02 100644 --- a/NuGet.Config +++ b/NuGet.Config @@ -8,6 +8,7 @@ + diff --git a/src/Microsoft.DotNet.Cli.Utils/AnsiConsole.cs b/src/Microsoft.DotNet.Cli.Utils/AnsiConsole.cs new file mode 100644 index 000000000..c47e877d1 --- /dev/null +++ b/src/Microsoft.DotNet.Cli.Utils/AnsiConsole.cs @@ -0,0 +1,143 @@ +// 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. + +using System; +using System.IO; + +namespace Microsoft.DotNet.Cli.Utils +{ + internal class AnsiConsole + { + private AnsiConsole(TextWriter writer, bool useConsoleColor) + { + Writer = writer; + + _useConsoleColor = useConsoleColor; + if (_useConsoleColor) + { + OriginalForegroundColor = Console.ForegroundColor; + } + } + + private int _boldRecursion; + private bool _useConsoleColor; + + public static AnsiConsole GetOutput(bool useConsoleColor) + { + return new AnsiConsole(Console.Out, useConsoleColor); + } + + public static AnsiConsole GetError(bool useConsoleColor) + { + return new AnsiConsole(Console.Error, useConsoleColor); + } + + public TextWriter Writer { get; } + + public ConsoleColor OriginalForegroundColor { get; } + + private void SetColor(ConsoleColor color) + { + Console.ForegroundColor = (ConsoleColor)(((int)Console.ForegroundColor & 0x08) | ((int)color & 0x07)); + } + + private void SetBold(bool bold) + { + _boldRecursion += bold ? 1 : -1; + if (_boldRecursion > 1 || (_boldRecursion == 1 && !bold)) + { + return; + } + + Console.ForegroundColor = (ConsoleColor)((int)Console.ForegroundColor ^ 0x08); + } + + public void WriteLine(string message) + { + if (!_useConsoleColor) + { + Writer.WriteLine(message); + return; + } + + var escapeScan = 0; + for (;;) + { + var escapeIndex = message.IndexOf("\x1b[", escapeScan); + if (escapeIndex == -1) + { + var text = message.Substring(escapeScan); + Writer.Write(text); + break; + } + else + { + var startIndex = escapeIndex + 2; + var endIndex = startIndex; + while (endIndex != message.Length && + message[endIndex] >= 0x20 && + message[endIndex] <= 0x3f) + { + endIndex += 1; + } + + var text = message.Substring(escapeScan, escapeIndex - escapeScan); + Writer.Write(text); + if (endIndex == message.Length) + { + break; + } + + switch (message[endIndex]) + { + case 'm': + int value; + if (int.TryParse(message.Substring(startIndex, endIndex - startIndex), out value)) + { + switch (value) + { + case 1: + SetBold(true); + break; + case 22: + SetBold(false); + break; + case 30: + SetColor(ConsoleColor.Black); + break; + case 31: + SetColor(ConsoleColor.Red); + break; + case 32: + SetColor(ConsoleColor.Green); + break; + case 33: + SetColor(ConsoleColor.Yellow); + break; + case 34: + SetColor(ConsoleColor.Blue); + break; + case 35: + SetColor(ConsoleColor.Magenta); + break; + case 36: + SetColor(ConsoleColor.Cyan); + break; + case 37: + SetColor(ConsoleColor.Gray); + break; + case 39: + SetColor(OriginalForegroundColor); + break; + } + } + break; + } + + escapeScan = endIndex + 1; + } + } + Writer.WriteLine(); + } + } +} diff --git a/src/Microsoft.DotNet.Cli.Utils/Command.cs b/src/Microsoft.DotNet.Cli.Utils/Command.cs index b78918321..c7154fb59 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Command.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Command.cs @@ -132,6 +132,8 @@ namespace Microsoft.DotNet.Cli.Utils public CommandResult Execute() { + Reporter.Verbose.WriteLine($"Running {_process.StartInfo.FileName} {_process.StartInfo.Arguments}"); + ThrowIfRunning(); _running = true; diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandContext.cs b/src/Microsoft.DotNet.Cli.Utils/CommandContext.cs index d9d79788c..50c5b4c22 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandContext.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandContext.cs @@ -33,12 +33,24 @@ namespace Microsoft.DotNet.Cli.Utils private static bool GetBool(string name, bool defaultValue = false) { var str = Environment.GetEnvironmentVariable(name); - bool value; - if(string.IsNullOrEmpty(str) || !bool.TryParse(str, out value)) + if (string.IsNullOrEmpty(str)) { return defaultValue; } - return value; + + switch (str.ToLowerInvariant()) + { + case "true": + case "1": + case "yes": + return true; + case "false": + case "0": + case "no": + return false; + default: + return defaultValue; + } } } } diff --git a/src/Microsoft.DotNet.Cli.Utils/Reporter.cs b/src/Microsoft.DotNet.Cli.Utils/Reporter.cs index 3ec488f39..7ac27702c 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Reporter.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Reporter.cs @@ -5,7 +5,6 @@ using System; using System.IO; using System.Runtime.InteropServices; using System.Text; -using Microsoft.Dnx.Runtime.Common.CommandLine; namespace Microsoft.DotNet.Cli.Utils { diff --git a/src/Microsoft.DotNet.Tools.Run/Program.cs b/src/Microsoft.DotNet.Tools.Run/Program.cs index 19eaa62cb..6bedd40dd 100644 --- a/src/Microsoft.DotNet.Tools.Run/Program.cs +++ b/src/Microsoft.DotNet.Tools.Run/Program.cs @@ -1,15 +1,9 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices; -using Microsoft.Dnx.Runtime.Common.CommandLine; using Microsoft.DotNet.Cli.Utils; -using Microsoft.Extensions.ProjectModel; -using NuGet.Frameworks; +using System; +using System.CommandLine; namespace Microsoft.DotNet.Tools.Run { @@ -19,52 +13,24 @@ namespace Microsoft.DotNet.Tools.Run { DebugHelper.HandleDebugSwitch(ref args); - var app = new CommandLineApplication(throwOnUnexpectedArg: false); - app.Name = "dotnet run"; - app.FullName = ".NET Executor"; - app.Description = "Runner for the .NET Platform"; - app.HelpOption("-h|--help"); + RunCommand runCmd = new RunCommand(); - var framework = app.Option("-f|--framework ", "Compile a specific framework", CommandOptionType.MultipleValue); - var configuration = app.Option("-c|--configuration ", "Configuration under which to build", CommandOptionType.SingleValue); - var preserveTemporaryOutput = app.Option("-t|--preserve-temporary", "Keep the output's temporary directory around", CommandOptionType.NoValue); - - // This is required to be an option because otherwise we can't tell if the first argument is a project or the first argument to pass to an application - var project = app.Option("-p|--project ", "The path to the project to run (defaults to the current directory). Can be a path to a project.json or a project directory.", CommandOptionType.SingleValue); - - app.OnExecute(() => + ArgumentSyntax.Parse(args, syntax => { - // Locate the project and get the name and full path - var path = project.Value(); - if (!string.IsNullOrEmpty(path)) - { - if (File.Exists(path) && (Path.GetExtension(path) == ".csx")) - { - return RunInteractive(path); - } - } - else - { - path = Directory.GetCurrentDirectory(); - } + syntax.HandleErrors = false; + syntax.DefineOption("f|framework", ref runCmd.Framework, "Compile a specific framework"); + syntax.DefineOption("c|configuration", ref runCmd.Configuration, "Configuration under which to build"); + syntax.DefineOption("t|preserve-temporary", ref runCmd.PreserveTemporary, "Keep the output's temporary directory around"); + syntax.DefineOption("p|project", ref runCmd.Project, "The path to the project to run (defaults to the current directory). Can be a path to a project.json or a project directory"); - var contexts = ProjectContext.CreateContextForEachFramework(path); - ProjectContext context; - if (!framework.HasValue()) - { - context = contexts.First(); - } - else - { - var fx = NuGetFramework.Parse(framework.Value()); - context = contexts.FirstOrDefault(c => c.TargetFramework.Equals(fx)); - } - return Run(context, configuration.Value() ?? Constants.DefaultConfiguration, app.RemainingArguments, preserveTemporaryOutput.HasValue()); + // TODO: this is not supporting args which can be switches (i.e. --test) + // TODO: we need to make a change in System.CommandLine or parse args ourselves. + syntax.DefineParameterList("args", ref runCmd.Args, "Arguments to pass to the executable or script"); }); try { - return app.Execute(args); + return runCmd.Start(); } catch (Exception ex) { @@ -76,77 +42,5 @@ namespace Microsoft.DotNet.Tools.Run return 1; } } - - private static int Run(ProjectContext context, string configuration, List remainingArguments, bool preserveTemporaryOutput) - { - // Create a temporary directory - var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); - - // Compile to that directory - var result = Command.Create($"dotnet-compile", $"--output \"{tempDir}\" --temp-output \"{tempDir}\" --framework \"{context.TargetFramework}\" --configuration \"{configuration}\" {context.ProjectFile.ProjectDirectory}") - .ForwardStdOut(onlyIfVerbose: true) - .ForwardStdErr() - .Execute(); - - if (result.ExitCode != 0) - { - return result.ExitCode; - } - - // Now launch the output and give it the results - var outputName = Path.Combine(tempDir, context.ProjectFile.Name + Constants.ExeSuffix); - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - if (context.TargetFramework.IsDesktop()) - { - // Run mono if we're running a desktop target on non windows - remainingArguments.Insert(0, outputName + ".exe"); - - if (string.Equals(configuration, "Debug", StringComparison.OrdinalIgnoreCase)) - { - // If we're compiling for the debug configuration then add the --debug flag - // other options may be passed using the MONO_OPTIONS env var - remainingArguments.Insert(0, "--debug"); - } - - outputName = "mono"; - } - } - - // Locate the runtime - string runtime = Environment.GetEnvironmentVariable("DOTNET_HOME"); - if (string.IsNullOrEmpty(runtime)) - { - // Use the runtime deployed with the tools, if present - var candidate = Path.Combine(AppContext.BaseDirectory, "..", "runtime"); - if (File.Exists(Path.Combine(candidate, Constants.LibCoreClrName))) - { - runtime = Path.GetFullPath(candidate); - } - } - - result = Command.Create(outputName, string.Join(" ", remainingArguments)) - .ForwardStdOut() - .ForwardStdErr() - .EnvironmentVariable("DOTNET_HOME", runtime) - .Execute(); - - // Clean up - if (!preserveTemporaryOutput) - { - Directory.Delete(tempDir, recursive: true); - } - - return result.ExitCode; - } - - private static int RunInteractive(string scriptName) - { - var command = Command.Create($"dotnet-repl-csi", scriptName) - .ForwardStdOut() - .ForwardStdErr(); - var result = command.Execute(); - return result.ExitCode; - } } } diff --git a/src/Microsoft.DotNet.Tools.Run/RunCommand.cs b/src/Microsoft.DotNet.Tools.Run/RunCommand.cs new file mode 100644 index 000000000..73d69a702 --- /dev/null +++ b/src/Microsoft.DotNet.Tools.Run/RunCommand.cs @@ -0,0 +1,158 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using Microsoft.DotNet.Cli.Utils; +using Microsoft.Extensions.ProjectModel; +using NuGet.Frameworks; + +namespace Microsoft.DotNet.Tools.Run +{ + public class RunCommand + { + public string Framework = null; + public string Configuration = null; + public bool PreserveTemporary = false; + public string Project = null; + public IReadOnlyList Args = null; + + ProjectContext _context; + List _args; + + public int Start() + { + if (IsInteractive()) + { + return RunInteractive(Project); + } + else + { + return RunExecutable(); + } + } + + private bool IsInteractive() + { + if (!string.IsNullOrEmpty(Project)) + { + if (File.Exists(Project) && (Path.GetExtension(Project).ToLowerInvariant() == ".csx")) + { + return true; + } + } + + return false; + } + + private void CalculateDefaultsForNonAssigned() + { + if (string.IsNullOrWhiteSpace(Project)) + { + Project = Directory.GetCurrentDirectory(); + } + + if (string.IsNullOrWhiteSpace(Configuration)) + { + Configuration = Constants.DefaultConfiguration; + } + + var contexts = ProjectContext.CreateContextForEachFramework(Project); + if (Framework == null) + { + _context = contexts.First(); + } + else + { + var fx = NuGetFramework.Parse(Framework); + _context = contexts.FirstOrDefault(c => c.TargetFramework.Equals(fx)); + } + + if (Args == null) + { + _args = new List(); + } + else + { + _args = new List(Args); + } + } + + private int RunExecutable() + { + CalculateDefaultsForNonAssigned(); + + // Create a temporary directory + var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); + + // Compile to that directory + var result = Command.Create($"dotnet-compile", $"--output \"{tempDir}\" --temp-output \"{tempDir}\" --framework \"{_context.TargetFramework}\" --configuration \"{Configuration}\" {_context.ProjectFile.ProjectDirectory}") + .ForwardStdOut(onlyIfVerbose: true) + .ForwardStdErr() + .Execute(); + + if (result.ExitCode != 0) + { + return result.ExitCode; + } + + // Now launch the output and give it the results + var outputName = Path.Combine(tempDir, _context.ProjectFile.Name + Constants.ExeSuffix); + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + if (_context.TargetFramework.IsDesktop()) + { + // Run mono if we're running a desktop target on non windows + _args.Insert(0, outputName + ".exe"); + + if (string.Equals(Configuration, "Debug", StringComparison.OrdinalIgnoreCase)) + { + // If we're compiling for the debug configuration then add the --debug flag + // other options may be passed using the MONO_OPTIONS env var + _args.Insert(0, "--debug"); + } + + outputName = "mono"; + } + } + + // Locate the runtime + string runtime = Environment.GetEnvironmentVariable("DOTNET_HOME"); + if (string.IsNullOrEmpty(runtime)) + { + // Use the runtime deployed with the tools, if present + var candidate = Path.Combine(AppContext.BaseDirectory, "..", "runtime"); + if (File.Exists(Path.Combine(candidate, Constants.LibCoreClrName))) + { + runtime = Path.GetFullPath(candidate); + } + } + + result = Command.Create(outputName, string.Join(" ", _args)) + .ForwardStdOut() + .ForwardStdErr() + .EnvironmentVariable("DOTNET_HOME", runtime) + .Execute(); + + // Clean up + if (!PreserveTemporary) + { + Directory.Delete(tempDir, recursive: true); + } + + return result.ExitCode; + } + + private static int RunInteractive(string scriptName) + { + var command = Command.Create($"dotnet-repl-csi", scriptName) + .ForwardStdOut() + .ForwardStdErr(); + var result = command.Execute(); + return result.ExitCode; + } + } +} diff --git a/src/Microsoft.DotNet.Tools.Run/project.json b/src/Microsoft.DotNet.Tools.Run/project.json index 2d75f21b5..99fac659d 100644 --- a/src/Microsoft.DotNet.Tools.Run/project.json +++ b/src/Microsoft.DotNet.Tools.Run/project.json @@ -16,11 +16,8 @@ "type": "build", "version": "1.0.0-*" }, - "Microsoft.Extensions.CommandLineUtils.Sources": { - "type": "build", - "version": "1.0.0-*" - }, - "Microsoft.Net.Compilers.netcore": "1.2.0-beta-20151117-04" + "Microsoft.Net.Compilers.netcore": "1.2.0-beta-20151117-04", + "System.CommandLine" : "0.1.0-d111815-3" }, "frameworks": { "dnxcore50": { } diff --git a/test/TestAppWithArgs/Program.cs b/test/TestAppWithArgs/Program.cs new file mode 100644 index 000000000..2ad9911f8 --- /dev/null +++ b/test/TestAppWithArgs/Program.cs @@ -0,0 +1,18 @@ +using System; + +namespace ConsoleApplication +{ + public class Program + { + public static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + + Console.WriteLine($"I was passed {args.Length} args:"); + foreach (var arg in args) + { + Console.WriteLine($"arg: [{arg}]"); + } + } + } +} diff --git a/test/TestAppWithArgs/project.json b/test/TestAppWithArgs/project.json new file mode 100644 index 000000000..9a9e91e40 --- /dev/null +++ b/test/TestAppWithArgs/project.json @@ -0,0 +1,17 @@ +{ + "version": "1.0.0-*", + "compilationOptions": { + "emitEntryPoint": true + }, + + "dependencies": { + "Microsoft.NETCore.Runtime": "1.0.1-beta-*", + "System.IO": "4.0.10-beta-*", + "System.Console": "4.0.0-beta-*", + "System.Runtime": "4.0.21-beta-*" + }, + + "frameworks": { + "dnxcore50": { } + } +}