2017-01-04 18:48:14 -08:00
|
|
|
// 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;
|
2017-01-05 13:05:36 -08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
2017-01-04 18:48:14 -08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-01-05 13:05:36 -08:00
|
|
|
var packageToRemove = RemainingArguments.First();
|
|
|
|
var result = NuGetCommand.Run(TransformArgs(packageToRemove, projectFilePath));
|
2017-01-04 18:48:14 -08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private string[] TransformArgs(string packageId, string projectFilePath)
|
|
|
|
{
|
|
|
|
return new string[]{
|
|
|
|
"package",
|
|
|
|
"remove",
|
|
|
|
"--package",
|
|
|
|
packageId,
|
|
|
|
"--project",
|
|
|
|
projectFilePath
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2017-03-02 20:35:20 -08:00
|
|
|
}
|