Adding dotnet remove package sub command
This commit is contained in:
parent
05b448944c
commit
a461cfbb2b
3 changed files with 94 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.DotNet.Cli;
|
using Microsoft.DotNet.Cli;
|
||||||
|
using Microsoft.DotNet.Tools.Remove.PackageReference;
|
||||||
using Microsoft.DotNet.Tools.Remove.ProjectFromSolution;
|
using Microsoft.DotNet.Tools.Remove.ProjectFromSolution;
|
||||||
using Microsoft.DotNet.Tools.Remove.ProjectToProjectReference;
|
using Microsoft.DotNet.Tools.Remove.ProjectToProjectReference;
|
||||||
|
|
||||||
|
@ -18,6 +19,7 @@ namespace Microsoft.DotNet.Tools.Remove
|
||||||
{
|
{
|
||||||
RemoveProjectFromSolutionCommand.Create,
|
RemoveProjectFromSolutionCommand.Create,
|
||||||
RemoveProjectToProjectReferenceCommand.Create,
|
RemoveProjectToProjectReferenceCommand.Create,
|
||||||
|
RemovePackageReferenceCommand.Create
|
||||||
};
|
};
|
||||||
|
|
||||||
public static int Run(string[] args)
|
public static int Run(string[] args)
|
||||||
|
|
|
@ -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 references to remove";
|
||||||
|
|
||||||
|
public const string SpecifyExactlyOnePackageReference = "Please specify one package reference to remove";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
// 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.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
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;
|
||||||
|
|
||||||
|
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 result = NuGetCommand.Run(TransformArgs(RemainingArguments.First(), projectFilePath));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string[] TransformArgs(string packageId, string projectFilePath)
|
||||||
|
{
|
||||||
|
return new string[]{
|
||||||
|
"package",
|
||||||
|
"remove",
|
||||||
|
"--package",
|
||||||
|
packageId,
|
||||||
|
"--project",
|
||||||
|
projectFilePath
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue