Merge pull request #5220 from mishra14/dev-anmishr-dotnetremovepackage

Adding dotnet remove package sub command
This commit is contained in:
Livar 2017-01-05 16:33:34 -08:00 committed by GitHub
commit 61dbfbf228
3 changed files with 95 additions and 0 deletions

View file

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Tools.Remove.PackageReference;
using Microsoft.DotNet.Tools.Remove.ProjectFromSolution;
using Microsoft.DotNet.Tools.Remove.ProjectToProjectReference;
@ -18,6 +19,7 @@ namespace Microsoft.DotNet.Tools.Remove
{
RemoveProjectFromSolutionCommand.Create,
RemoveProjectToProjectReferenceCommand.Create,
RemovePackageReferenceCommand.Create
};
public static int Run(string[] args)

View file

@ -0,0 +1,17 @@
// 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.
namespace Microsoft.DotNet.Tools.Remove.PackageReference
{
internal class LocalizableStrings
{
public const string AppFullName = ".NET Remove Package reference Command.";
public const string AppDescription = "Command to remove package reference.";
public const string AppHelpText = "Package reference to remove.";
public const string SpecifyExactlyOnePackageReference = "Please specify only one package reference to remove.";
}
}

View file

@ -0,0 +1,76 @@
// 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 Microsoft.Build.Evaluation;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Common;
using Microsoft.DotNet.Tools.MSBuild;
using Microsoft.DotNet.Tools.NuGet;
using NuGet.Frameworks;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace Microsoft.DotNet.Tools.Remove.PackageReference
{
internal class RemovePackageReferenceCommand : DotNetSubCommandBase
{
public static DotNetSubCommandBase Create()
{
var command = new RemovePackageReferenceCommand
{
Name = "package",
FullName = LocalizableStrings.AppFullName,
Description = LocalizableStrings.AppDescription,
HandleRemainingArguments = true,
ArgumentSeparatorHelpText = LocalizableStrings.AppHelpText,
};
command.HelpOption("-h|--help");
return command;
}
public override int Run(string fileOrDirectory)
{
if (RemainingArguments.Count != 1)
{
throw new GracefulException(LocalizableStrings.SpecifyExactlyOnePackageReference);
}
var projectFilePath = string.Empty;
if (!File.Exists(fileOrDirectory))
{
projectFilePath = MsbuildProject.GetProjectFileFromDirectory(fileOrDirectory).FullName;
}
else
{
projectFilePath = fileOrDirectory;
}
var packageToRemove = RemainingArguments.First();
var result = NuGetCommand.Run(TransformArgs(packageToRemove, projectFilePath));
return result;
}
private string[] TransformArgs(string packageId, string projectFilePath)
{
return new string[]{
"package",
"remove",
"--package",
packageId,
"--project",
projectFilePath
};
}
}
}