Merge Nuget changes

Fix pack
Move dotnet-nuget to NuGetForwardingApp [tests will need to be fixed]
This commit is contained in:
PiotrP 2016-08-26 17:23:33 -07:00
parent ed66c70106
commit 336ecc0e89
7 changed files with 28 additions and 87 deletions

View file

@ -6,7 +6,7 @@ using System.Collections.Generic;
using System.IO;
using Microsoft.DotNet.Cli;
namespace Microsoft.DotNet.Tools.Restore
namespace Microsoft.DotNet.Tools
{
public class NuGetForwardingApp
{

View file

@ -1,9 +0,0 @@
// 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.NuGet
{
public interface INuGetCommandRunner
{
int Run(string[] commandArgs);
}
}

View file

@ -1,73 +0,0 @@
// 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.Linq;
using System.Reflection;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using NugetProgram = NuGet.CommandLine.XPlat.Program;
namespace Microsoft.DotNet.Tools.NuGet
{
public class NuGetCommand
{
public static int Run(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);
var app = new CommandLineApplication(false)
{
Name = "dotnet nuget",
FullName = ".NET NuGet command runner",
Description = "For running NuGet commands (\"dotnet nuget --help\" for specifics)"
};
app.OnExecute(() =>
{
try
{
return RunCommand(args, new NuGetCommandRunner());
}
catch (InvalidOperationException e)
{
Console.WriteLine(e.Message);
return -1;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return -2;
}
});
return app.Execute(args);
}
public static int RunCommand(IEnumerable<string> args, INuGetCommandRunner commandRunner)
{
Debug.Assert(commandRunner != null, "A command runner must be passed to RunCommand");
if (commandRunner == null)
{
throw new InvalidOperationException("No command runner supplied to RunCommand");
}
return commandRunner.Run(args.ToArray());
}
private class NuGetCommandRunner : INuGetCommandRunner
{
public int Run(string[] commandArgs)
{
var nugetAsm = typeof(NugetProgram).GetTypeInfo().Assembly;
var mainMethod = nugetAsm.EntryPoint;
return (int)mainMethod.Invoke(null, new object[] { commandArgs });
}
}
}
}

View file

@ -0,0 +1,24 @@
// 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.Linq;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.InternalAbstractions;
using Microsoft.DotNet.Tools;
namespace Microsoft.DotNet.Tools.Restore
{
public partial class NuGetCommand
{
public static int Run(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);
var nugetApp = new NuGetForwardingApp(args);
return nugetApp.Execute();
}
}
}

View file

@ -18,8 +18,8 @@ using NuGet.Legacy;
using NuGet.Frameworks;
using NuGet.Packaging.Core;
using NuGet.Versioning;
using PackageBuilder = NuGet.PackageBuilder;
using NuGetConstants = NuGet.Constants;
using PackageBuilder = NuGet.Legacy.PackageBuilder;
using NuGetConstants = NuGet.Legacy.Constants;
namespace Microsoft.DotNet.Tools.Compiler
{

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.Tools;
namespace Microsoft.DotNet.Tools.Restore
{

View file

@ -11,8 +11,6 @@ namespace Microsoft.DotNet.Tools.Restore
{
public partial class RestoreCommand
{
private static readonly string DefaultRid = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier();
public static int Run(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);