-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Adding dotnet add package sub command #5122
Adding dotnet add package sub command #5122
Conversation
Hi @mishra14, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution! The agreement was validated by .NET Foundation and real humans are currently evaluating your PR. TTYL, DNFBOT; |
@dotnet-bot test Debian8.2 x64 Debug Build |
@dotnet-bot test Windows_NT x64 Release Build |
@dotnet-bot test Ubuntu x64 Release Build |
|
||
namespace Microsoft.DotNet.Tools.Add.PackageReference | ||
{ | ||
internal class LocalizableStrings |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
public static DotNetSubCommandBase Create() | ||
{ | ||
var command = new AddPackageReferenceCommand() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
public override int Run(string fileOrDirectory) | ||
{ | ||
var projects = new ProjectCollection(); | ||
var msbuildProj = MsbuildProject.FromFileOrDirectory(projects, fileOrDirectory); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return result; | ||
} | ||
|
||
private void GetProjectDependencyGraph(string projectFilePath, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
args.Add("/t:GenerateRestoreGraphFile"); | ||
|
||
// Pass Dependency Graph file output path | ||
args.Add(string.Format("/p:RestoreGraphOutputPath={0}{1}{2}", '"', dgFilePath, '"')); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
if (result != 0) | ||
{ | ||
throw new GracefulException(string.Format(LocalizableStrings.CmdDGFileException, projectFilePath)); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
} | ||
|
||
private string CreateTemporaryFile(string extension) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
public override int Run(string fileOrDirectory) | ||
{ | ||
var projects = new ProjectCollection(); | ||
var msbuildProj = MsbuildProject.FromFileOrDirectory(projects, fileOrDirectory); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
"package", | ||
"add", | ||
"--package", | ||
"Newtonsoft.Json", |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
"Newtonsoft.Json", | ||
"--project", | ||
projectFilePath | ||
}; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@dotnet-bot test CentOS7.1 x64 Debug Build |
@@ -62,6 +62,19 @@ public static MsbuildProject FromFile(ProjectCollection projects, string project | |||
|
|||
public static MsbuildProject FromDirectory(ProjectCollection projects, string projectDirectory) | |||
{ | |||
FileInfo projectFile = GetProjectFileFromDirectory(projectDirectory); | |||
|
|||
var project = TryOpenProject(projects, projectFile.FullName); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
return new MsbuildProject(projects, project); | ||
return files.First(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
GetProjectDependencyGraph(projectFilePath, tempDgFilePath); | ||
} | ||
|
||
var result = NuGetCommand.Run(TransformArgs(RemainingArguments.First(), tempDgFilePath, projectFilePath)); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
else | ||
{ | ||
projectFilePath = fileOrDirectory; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
"package", | ||
"add", | ||
"--package", | ||
packageId, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -270,4 +268,4 @@ private static ProjectRootElement TryOpenProject(ProjectCollection projects, str | |||
} | |||
} | |||
} | |||
} | |||
} |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -26,4 +28,4 @@ public static int Run(string[] args) | |||
return command.RunCommand(args); | |||
} | |||
} | |||
} | |||
} |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Adding the
dotnet add package
sub command to add package references.NuGet part of the work : NuGet/NuGet.Client#1063
Fixes add package part of https://github.com/dotnet/cli/issues/4521 and NuGet/Home#3751
//cc: @livarcocc @piotrpMSFT @blackdwarf @krwq @rrelyea @emgarten