Add nuget command to dotnet cli

This commit is contained in:
drewgil 2016-08-10 10:50:18 -07:00
parent 49527d3ea6
commit 11b666acee
31 changed files with 237 additions and 25 deletions

View file

@ -93,6 +93,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-dependency-tool-invo
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Compiler.Common.Tests", "test\Microsoft.DotNet.Compiler.Common.Tests\Microsoft.DotNet.Compiler.Common.Tests.xproj", "{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-nuget.UnitTests", "test\dotnet-nuget.UnitTests\dotnet-nuget.UnitTests.xproj", "{2EC08501-CFC6-412F-9345-8D31D258A60E}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-pack.Tests", "test\dotnet-pack.Tests\dotnet-pack.Tests.xproj", "{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "dotnet-run.Tests", "test\dotnet-run.Tests\dotnet-run.Tests.xproj", "{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F}"
@ -663,6 +665,22 @@ Global
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.Debug|x64.ActiveCfg = Debug|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.Debug|x64.Build.0 = Debug|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.Release|Any CPU.Build.0 = Release|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.Release|x64.ActiveCfg = Release|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.Release|x64.Build.0 = Release|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{2EC08501-CFC6-412F-9345-8D31D258A60E}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4}.Debug|x64.ActiveCfg = Debug|Any CPU
@ -946,6 +964,7 @@ Global
{1AB5B24B-B317-4142-A5D1-A6E84F15BA34} = {ADA7052B-884B-4776-8B8D-D04191D0AA70}
{C26A48BB-193F-450C-AB09-4D3324C78188} = {1AB5B24B-B317-4142-A5D1-A6E84F15BA34}
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{2EC08501-CFC6-412F-9345-8D31D258A60E} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{5FDA6D37-3A3E-4333-BA5C-F0B28BE316F4} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{35E3C2DC-9B38-4EC5-8DD7-C32458DC485F} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{6A3095FF-A7C5-4300-85A9-C025C384401D} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}

View file

@ -27,6 +27,7 @@ namespace Microsoft.DotNet.Cli.Build
// TODO: https://github.com/dotnet/cli/issues/3558
// "dotnet-compile-fsc.Tests",
"dotnet-new.Tests",
"dotnet-nuget.UnitTests",
"dotnet-pack.Tests",
"dotnet-projectmodel-server.Tests",
"dotnet-publish.Tests",

View file

@ -16,6 +16,7 @@ using Microsoft.DotNet.Tools.Compiler;
using Microsoft.DotNet.Tools.Compiler.Csc;
using Microsoft.DotNet.Tools.Help;
using Microsoft.DotNet.Tools.New;
using Microsoft.DotNet.Tools.NuGet;
using Microsoft.DotNet.Tools.Publish;
using Microsoft.DotNet.Tools.Restore;
using Microsoft.DotNet.Tools.Run;
@ -32,6 +33,7 @@ namespace Microsoft.DotNet.Cli
["compile-csc"] = CompileCscCommand.Run,
["help"] = HelpCommand.Run,
["new"] = NewCommand.Run,
["nuget"] = NuGetCommand.Run,
["pack"] = PackCommand.Run,
["projectmodel-server"] = ProjectModelServerCommand.Run,
["publish"] = PublishCommand.Run,

View file

@ -0,0 +1,9 @@
// 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

@ -0,0 +1,73 @@
// 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

@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
namespace NuGet
namespace NuGet.Legacy
{
public static class Constants
{

View file

@ -4,7 +4,7 @@
using System;
using System.IO;
namespace NuGet
namespace NuGet.Legacy
{
/// <summary>
/// Represents an empty framework folder in NuGet 2.0+ packages.

View file

@ -5,7 +5,7 @@ using System;
using System.Collections.Generic;
using NuGet.Frameworks;
namespace NuGet
namespace NuGet.Legacy
{
public class FrameworkAssemblyReference
{

View file

@ -3,7 +3,7 @@
using System.IO;
namespace NuGet
namespace NuGet.Legacy
{
public interface IPackageFile
{

View file

@ -8,7 +8,7 @@ using System.IO;
using System.Linq;
using System.Xml.Linq;
namespace NuGet
namespace NuGet.Legacy
{
public class Manifest
{

View file

@ -1,7 +1,7 @@
// 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 NuGet
namespace NuGet.Legacy
{
public class ManifestContentFiles
{

View file

@ -1,7 +1,7 @@
// 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 NuGet
namespace NuGet.Legacy
{
public class ManifestFile
{

View file

@ -7,7 +7,7 @@ using System.IO;
using System.Linq;
using NuGet.Versioning;
namespace NuGet
namespace NuGet.Legacy
{
public class ManifestMetadata
{

View file

@ -14,7 +14,7 @@ using System.Xml;
using System.Xml.Linq;
// TODO: Resources using NuGet.Resources;
namespace NuGet
namespace NuGet.Legacy
{
internal static class ManifestReader
{

View file

@ -5,7 +5,7 @@ using System;
using System.Globalization;
using System.Linq;
namespace NuGet
namespace NuGet.Legacy
{
internal static class ManifestSchemaUtility
{

View file

@ -3,7 +3,7 @@
using System;
namespace NuGet
namespace NuGet.Legacy
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
internal sealed class ManifestVersionAttribute : Attribute

View file

@ -6,7 +6,7 @@ using System.Collections;
using System.Linq;
using System.Reflection;
namespace NuGet
namespace NuGet.Legacy
{
internal static class ManifestVersionUtility
{

View file

@ -13,7 +13,7 @@ using NuGet.Packaging;
using NuGet.Packaging.Core;
using NuGet.Versioning;
namespace NuGet
namespace NuGet.Legacy
{
public class PackageBuilder
{

View file

@ -7,7 +7,7 @@ using System.Linq;
using NuGet.Frameworks;
using NuGet.Packaging.Core;
namespace NuGet
namespace NuGet.Legacy
{
public class PackageDependencySet
{

View file

@ -5,7 +5,7 @@ using System;
using System.Globalization;
using System.Text.RegularExpressions;
namespace NuGet
namespace NuGet.Legacy
{
public static class PackageIdValidator
{

View file

@ -9,7 +9,7 @@ using NuGet.Frameworks;
using NuGet.Packaging.Core;
using NuGet.Versioning;
namespace NuGet
namespace NuGet.Legacy
{
internal static class PackageMetadataXmlExtensions
{

View file

@ -6,7 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using NuGet.Frameworks;
namespace NuGet
namespace NuGet.Legacy
{
public class PackageReferenceSet
{

View file

@ -7,7 +7,7 @@ using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace NuGet
namespace NuGet.Legacy
{
public static class PathResolver
{

View file

@ -4,7 +4,7 @@
using System;
using System.IO;
namespace NuGet
namespace NuGet.Legacy
{
internal static class PathUtility
{

View file

@ -4,7 +4,7 @@
using System;
using System.IO;
namespace NuGet
namespace NuGet.Legacy
{
public class PhysicalPackageFile : IPackageFile
{

View file

@ -14,11 +14,11 @@ using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.ProjectModel.Resources;
using Microsoft.DotNet.ProjectModel.Utilities;
using Microsoft.DotNet.Tools.Pack;
using NuGet;
using NuGet.Legacy;
using NuGet.Frameworks;
using NuGet.Packaging.Core;
using NuGet.Versioning;
using PackageBuilder = NuGet.PackageBuilder;
using PackageBuilder = NuGet.Legacy.PackageBuilder;
namespace Microsoft.DotNet.Tools.Compiler
{
@ -58,7 +58,7 @@ namespace Microsoft.DotNet.Tools.Compiler
var packageOutputPath = Path.Combine(
ArtifactPathsCalculator.PackageOutputPath,
GetPackageName() + NuGet.Constants.PackageExtension);
GetPackageName() + global::NuGet.Legacy.Constants.PackageExtension);
if (GeneratePackage(packageOutputPath, packDiagnostics))
{

View file

@ -6,7 +6,7 @@ using System.IO;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Files;
using Microsoft.DotNet.Tools.Pack;
using NuGet;
using NuGet.Legacy;
namespace Microsoft.DotNet.Tools.Compiler
{

View file

@ -18,4 +18,4 @@
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
</Project>

View file

@ -0,0 +1,59 @@
// 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.Collections.Generic;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.DotNet.Tools.NuGet;
using Moq;
using NuGet.Frameworks;
using Xunit;
namespace Microsoft.DotNet.Tools.Run.Tests
{
public class GivenANuGetCommand : TestBase
{
[Theory]
[InlineData(new[] { "push", "foo.1.0.0.nupkg" }, 0)]
[InlineData(new[] { "push", "foo.1.0.0.nupkg", "-k", "12345678-1234-1234-1234-123456789012" }, 0)]
[InlineData(new[] { "push", "foo.1.0.0.nupkg",
"--api-key", "12345678-1234-1234-1234-123456789012",
"--source", "http://www.myget.org/foofeed" }, 0)]
[InlineData(new[] { "push", "foo.1.0.0.nupkg",
"--api-key", "12345678-1234-1234-1234-123456789012",
"--source", "http://www.nuget.org/foofeed",
"--symbol-api-key", "12345678-1234-1234-1234-123456789012",
"--symbol-source", "https://nuget.smbsrc.net/foo",
"--timeout", "1000",
"--disable-buffering",
"--no-symbols" }, 0)] // Unlikely option given others, but testing max options edge case
[InlineData(new[] { "delete", "foo.1.0.0.nupkg" }, 0)]
[InlineData(new[] { "delete", "foo.1.0.0.nupkg",
"--non-interactive" }, 0)]
[InlineData(new[] { "delete", "foo.1.0.0.nupkg",
"--api-key", "12345678-1234-1234-1234-123456789012",
"--source", "http://www.nuget.org/foofeed",
"--non-interactive" }, 0)]
[InlineData(new[] { "locals" }, 0)]
[InlineData(new[] { "locals", "http-cache", "packages-cache", "global-packages", "temp" }, 0)]
public void ItPassesCommandIfSupported(string[] inputArgs, int result)
{
// Arrange
string[] receivedArgs = null;
var testCommandRunner = new Mock<INuGetCommandRunner>();
testCommandRunner
.Setup(x => x.Run(It.IsAny<string[]>()))
.Callback<string[]>(s => receivedArgs = s)
.Returns(0);
// Act
var returned = NuGetCommand.RunCommand(inputArgs, testCommandRunner.Object);
// Assert
receivedArgs.Should().BeEquivalentTo(inputArgs);
returned.Should().Be(result);
}
}
}

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.24720" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.24720</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>2EC08501-CFC6-412F-9345-8D31D258A60E</ProjectGuid>
<RootNamespace>Microsoft.DotNet.Tools.NuGet.UnitTests</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View file

@ -0,0 +1,28 @@
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"System.Runtime.Serialization.Primitives": "4.1.1",
"dotnet": {
"target": "project"
},
"Microsoft.DotNet.Tools.Tests.Utilities": {
"target": "project"
},
"xunit": "2.1.0",
"moq.netcore": "4.4.0-beta8",
"dotnet-test-xunit": "1.0.0-rc2-192208-24"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.4",
"portable-net451+win8"
]
}
},
"testRunner": "xunit"
}