diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 429f4567a..5265a75e2 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -24,6 +24,7 @@ using Microsoft.DotNet.Tools.Run; using Microsoft.DotNet.Tools.Test; using Microsoft.DotNet.Tools.VSTest; using NuGet.Frameworks; +using Microsoft.DotNet.Tools.Add; namespace Microsoft.DotNet.Cli { @@ -45,6 +46,7 @@ namespace Microsoft.DotNet.Cli ["run"] = RunCommand.Run, ["test"] = TestCommand.Run, ["vstest"] = VSTestCommand.Run, + ["add"] = AddCommand.Run, }; public static int Main(string[] args) diff --git a/src/dotnet/commands/dotnet-add/Program.cs b/src/dotnet/commands/dotnet-add/Program.cs new file mode 100644 index 000000000..5c9a5b359 --- /dev/null +++ b/src/dotnet/commands/dotnet-add/Program.cs @@ -0,0 +1,68 @@ +// 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.Collections.Generic; +using Microsoft.DotNet.Cli.CommandLine; +using Microsoft.DotNet.Cli.Utils; +using System; +using System.IO; +using System.Linq; +using Microsoft.Build.Construction; +using Microsoft.DotNet.ProjectJsonMigration; +using NuGet.Frameworks; + +namespace Microsoft.DotNet.Tools.Add +{ + public class AddCommand + { + public const string CommandName = "dotnet-add"; + public const string UsageText = @"Usage: dotnet add [command] [arguments] + +Arguments: + [command] The command to execute + [arguments] Arguments to pass to the command + +Commands: + p2p Add project to project (p2p) reference to a project"; + + private static Dictionary> s_builtIns = new Dictionary> + { + ["p2p"] = null, + }; + + public static int Run(string[] args) + { + DebugHelper.HandleDebugSwitch(ref args); + + if (args.Length == 0 || args[0] == "--help" || args[0] == "-h") + { + Reporter.Output.WriteLine(UsageText); + return 1; + } + + if (args[0].StartsWith("-")) + { + Reporter.Error.WriteLine($"Unknown option: {args[0]}"); + Reporter.Output.WriteLine(UsageText); + return 1; + } + + string command = args[0]; + Func builtIn; + args = args.Skip(1).ToArray(); + if (s_builtIns.TryGetValue(command, out builtIn)) + { + return builtIn(args); + } + else + { + CommandResult result = Command.Create( + $"{CommandName}-{command}", + args, + FrameworkConstants.CommonFrameworks.NetStandardApp15) + .Execute(); + return result.ExitCode; + } + } + } +} diff --git a/src/dotnet/commands/dotnet-help/HelpCommand.cs b/src/dotnet/commands/dotnet-help/HelpCommand.cs index 5abe53b92..e520ce827 100644 --- a/src/dotnet/commands/dotnet-help/HelpCommand.cs +++ b/src/dotnet/commands/dotnet-help/HelpCommand.cs @@ -36,6 +36,7 @@ Commands: migrate Migrates a project.json based project to a msbuild based project Advanced Commands: + add Group of commands - run `dotnet add --help` for more information nuget Provides additional NuGet commands msbuild msbuilds a project and all of its dependencies vstest Runs tests from the specified files";