dotnet-installer/src/dotnet/commands/dotnet-remove/dotnet-remove-p2p/Program.cs

57 lines
1.9 KiB
C#
Raw Normal View History

// 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.
2016-12-08 14:56:31 -08:00
using Microsoft.Build.Evaluation;
2016-12-16 01:04:09 -08:00
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils;
namespace Microsoft.DotNet.Tools.Remove.ProjectToProjectReference
{
2016-12-16 01:04:09 -08:00
internal class RemoveProjectToProjectReferenceCommand : DotNetSubCommandBase
{
2016-12-15 13:40:46 -08:00
private CommandOption _frameworkOption;
2016-12-16 01:04:09 -08:00
public static DotNetSubCommandBase Create()
2016-12-15 13:40:46 -08:00
{
2016-12-16 01:04:09 -08:00
var command = new RemoveProjectToProjectReferenceCommand()
{
Name = "p2p",
FullName = LocalizableStrings.AppFullName,
Description = LocalizableStrings.AppDescription,
HandleRemainingArguments = true,
ArgumentSeparatorHelpText = LocalizableStrings.AppHelpText,
};
command.HelpOption("-h|--help");
command._frameworkOption = command.Option(
$"-f|--framework <{CommonLocalizableStrings.CmdFramework}>",
LocalizableStrings.CmdFrameworkDescription,
CommandOptionType.SingleValue);
return command;
2016-12-15 13:40:46 -08:00
}
2016-12-16 01:04:09 -08:00
public override int Run(string fileOrDirectory)
2016-12-15 13:40:46 -08:00
{
2016-12-16 01:04:09 -08:00
var msbuildProj = MsbuildProject.FromFileOrDirectory(new ProjectCollection(), fileOrDirectory);
if (RemainingArguments.Count == 0)
2016-12-15 13:40:46 -08:00
{
throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneReferenceToRemove);
}
2016-12-16 01:04:09 -08:00
int numberOfRemovedReferences = msbuildProj.RemoveProjectToProjectReferences(
2016-12-15 13:40:46 -08:00
_frameworkOption.Value(),
2016-12-16 01:04:09 -08:00
RemainingArguments);
2016-12-15 13:40:46 -08:00
if (numberOfRemovedReferences != 0)
{
2016-12-16 01:04:09 -08:00
msbuildProj.ProjectRootElement.Save();
2016-12-15 13:40:46 -08:00
}
2016-12-16 01:04:09 -08:00
return 0;
}
}
}