diff --git a/src/dotnet/CommandLine/CommandLineApplication.cs b/src/dotnet/CommandLine/CommandLineApplication.cs index f440a5595..fc859dd14 100644 --- a/src/dotnet/CommandLine/CommandLineApplication.cs +++ b/src/dotnet/CommandLine/CommandLineApplication.cs @@ -56,28 +56,33 @@ namespace Microsoft.DotNet.Cli.CommandLine public bool HandleRemainingArguments { get; set; } public string ArgumentSeparatorHelpText { get; set; } - public CommandLineApplication Command(string name, bool throwOnUnexpectedArg = true) + public CommandLineApplication AddCommand(string name, bool throwOnUnexpectedArg = true) { - return Command(name, _ => { }, throwOnUnexpectedArg); + return AddCommand(name, _ => { }, throwOnUnexpectedArg); } - public CommandLineApplication Command(string name, Action configuration, + public CommandLineApplication AddCommand(string name, Action configuration, bool throwOnUnexpectedArg = true) { var command = new CommandLineApplication(throwOnUnexpectedArg) { Name = name }; - return Command(command, configuration, throwOnUnexpectedArg); + return AddCommand(command, configuration, throwOnUnexpectedArg); } - public CommandLineApplication Command(CommandLineApplication command, bool throwOnUnexpectedArg = true) + public CommandLineApplication AddCommand(CommandLineApplication command, bool throwOnUnexpectedArg = true) { - return Command(command, _ => { }, throwOnUnexpectedArg); + return AddCommand(command, _ => { }, throwOnUnexpectedArg); } - public CommandLineApplication Command( + public CommandLineApplication AddCommand( CommandLineApplication command, Action configuration, bool throwOnUnexpectedArg = true) { + if (command == null || configuration == null) + { + throw new NullReferenceException(); + } + command.Parent = this; Commands.Add(command); configuration(command); diff --git a/src/dotnet/DotNetTopLevelCommandBase.cs b/src/dotnet/DotNetTopLevelCommandBase.cs index 4e0483503..8f547b86f 100644 --- a/src/dotnet/DotNetTopLevelCommandBase.cs +++ b/src/dotnet/DotNetTopLevelCommandBase.cs @@ -37,7 +37,7 @@ namespace Microsoft.DotNet.Cli foreach (var subCommandCreator in SubCommands) { var subCommand = subCommandCreator(); - command.Command(subCommand); + command.AddCommand(subCommand); subCommand.OnExecute(() => { try diff --git a/src/dotnet/commands/dotnet-add/dotnet-add-p2p/Program.cs b/src/dotnet/commands/dotnet-add/dotnet-add-p2p/Program.cs index 6107b122d..47c031bc6 100644 --- a/src/dotnet/commands/dotnet-add/dotnet-add-p2p/Program.cs +++ b/src/dotnet/commands/dotnet-add/dotnet-add-p2p/Program.cs @@ -41,7 +41,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference public override int Run(string fileOrDirectory) { - ProjectCollection projects = new ProjectCollection(); + var projects = new ProjectCollection(); MsbuildProject msbuildProj = MsbuildProject.FromFileOrDirectory(projects, fileOrDirectory); if (RemainingArguments.Count == 0) @@ -51,7 +51,9 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference string frameworkString = _frameworkOption.Value(); PathUtility.EnsureAllPathsExist(RemainingArguments, CommonLocalizableStrings.ReferenceDoesNotExist); - IEnumerable refs = RemainingArguments.Select((r) => MsbuildProject.FromFile(projects, r)); + List refs = RemainingArguments + .Select((r) => MsbuildProject.FromFile(projects, r)) + .ToList(); if (frameworkString == null) { @@ -108,7 +110,7 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToProjectReference return 0; } - private string GetProjectNotCompatibleWithFrameworksDisplayString(MsbuildProject project, IEnumerable frameworksDisplayStrings) + private static string GetProjectNotCompatibleWithFrameworksDisplayString(MsbuildProject project, IEnumerable frameworksDisplayStrings) { var sb = new StringBuilder(); sb.AppendLine(string.Format(CommonLocalizableStrings.ProjectNotCompatibleWithFrameworks, project.ProjectRootElement.FullPath));