{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/cli/pulls/comments/93565793","pull_request_review_id":14095683,"id":93565793,"diff_hunk":"@@ -0,0 +1,174 @@\n+// Copyright (c) .NET Foundation and contributors. All rights reserved.\n+// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n+\n+using System;\n+using System.Collections.Generic;\n+using System.Diagnostics;\n+using System.IO;\n+using System.Linq;\n+using System.Text;\n+using Microsoft.Build.Evaluation;\n+using Microsoft.DotNet.Cli;\n+using Microsoft.DotNet.Cli.CommandLine;\n+using Microsoft.DotNet.Cli.Utils;\n+using Microsoft.DotNet.Tools.Common;\n+using Microsoft.DotNet.Tools.MSBuild;\n+using Microsoft.DotNet.Tools.NuGet;\n+using NuGet.Frameworks;\n+\n+namespace Microsoft.DotNet.Tools.Add.PackageReference\n+{\n+    internal class AddPackageReferenceCommand : DotNetSubCommandBase\n+    {\n+        private CommandOption _versionOption;\n+        private CommandOption _frameworkOption;\n+        private CommandOption _noRestoreOption;\n+        private CommandOption _sourceOption;\n+        private CommandOption _packageDirectoryOption;\n+\n+        public static DotNetSubCommandBase Create()\n+        {\n+            var command = new AddPackageReferenceCommand()\n+            {\n+                Name = \"package\",\n+                FullName = LocalizableStrings.AppFullName,\n+                Description = LocalizableStrings.AppDescription,\n+                HandleRemainingArguments = true,\n+                ArgumentSeparatorHelpText = LocalizableStrings.AppHelpText,\n+            };\n+\n+            command.HelpOption(\"-h|--help\");\n+\n+            command._versionOption = command.Option(\n+                $\"-v|--version <{LocalizableStrings.CmdVersion}>\",\n+                LocalizableStrings.CmdVersionDescription,\n+                CommandOptionType.SingleValue);\n+\n+            command._frameworkOption = command.Option(\n+               $\"-f|--framework <{LocalizableStrings.CmdFramework}>\",\n+               LocalizableStrings.CmdFrameworkDescription,\n+               CommandOptionType.SingleValue);\n+\n+            command._noRestoreOption = command.Option(\n+                \"-n|--no-restore \",\n+               LocalizableStrings.CmdNoRestoreDescription,\n+               CommandOptionType.NoValue);\n+\n+            command._sourceOption = command.Option(\n+                $\"-s|--source <{LocalizableStrings.CmdSource}>\",\n+                LocalizableStrings.CmdSourceDescription,\n+                CommandOptionType.SingleValue);\n+\n+            command._packageDirectoryOption = command.Option(\n+                $\"--package-directory <{LocalizableStrings.CmdPackageDirectory}>\",\n+                LocalizableStrings.CmdPackageDirectoryDescription,\n+                CommandOptionType.SingleValue);\n+\n+            return command;\n+        }\n+\n+        public override int Run(string fileOrDirectory)\n+        {\n+            var projects = new ProjectCollection();\n+            var msbuildProj = MsbuildProject.FromFileOrDirectory(projects, fileOrDirectory);\n+\n+            if (RemainingArguments.Count == 0)\n+            {\n+                throw new GracefulException(CommonLocalizableStrings.SpecifyAtLeastOneReferenceToAdd);\n+            }\n+\n+            var tempDgFilePath = string.Empty;\n+            if(!_noRestoreOption.HasValue())\n+            {\n+                // Create a Dependency Graph file for the project\n+                tempDgFilePath = CreateTemporaryFile(\".dg\");\n+                GetProjectDependencyGraph(msbuildProj.ProjectRootElement.FullPath, tempDgFilePath);\n+            }\n+\n+            var result = NuGetCommand.Run(TransformArgs(tempDgFilePath, msbuildProj.ProjectRootElement.FullPath));\n+            DisposeTemporaryFile(tempDgFilePath);\n+            return result;\n+        }\n+\n+        private void GetProjectDependencyGraph(string projectFilePath,\n+            string dgFilePath)\n+        {\n+            var args = new List<string>();\n+\n+            // Pass the project file path\n+            args.Add(projectFilePath);\n+\n+            // Pass the task as generate restore Dependency Graph file\n+            args.Add(\"/t:GenerateRestoreGraphFile\");\n+\n+            // Pass Dependency Graph file output path\n+            args.Add(string.Format(\"/p:RestoreGraphOutputPath={0}{1}{2}\", '\"', dgFilePath, '\"'));\n+\n+            var result = new MSBuildForwardingApp(args).Execute();\n+\n+            if (result != 0)\n+            {\n+                throw new GracefulException(string.Format(LocalizableStrings.CmdDGFileException, projectFilePath));\n+            }\n+        }\n+\n+        private string CreateTemporaryFile(string extension)\n+        {\n+            var tempDirectory = Path.GetTempPath();\n+            var tempFile = Path.Combine(tempDirectory, Guid.NewGuid().ToString() + extension);\n+            File.Create(tempFile).Dispose();\n+            return tempFile;\n+        }\n+\n+        private void DisposeTemporaryFile(string filePath)\n+        {\n+            if (File.Exists(filePath))\n+            {\n+                File.Delete(filePath);\n+            }\n+        }\n+\n+        private string[] TransformArgs(string tempDgFilePath, string projectFilePath)\n+        {\n+            var args = new List<string>(){\n+                \"package\",\n+                \"add\",\n+                \"--package\",\n+                \"Newtonsoft.Json\",","path":"src/dotnet/commands/dotnet-add/dotnet-add-package/Program.cs","position":137,"original_position":137,"commit_id":"2738ea8a5a7101c80b301e73fe084206cea59339","original_commit_id":"2738ea8a5a7101c80b301e73fe084206cea59339","user":{"login":"livarcocc","id":367554,"avatar_url":"https://avatars.githubusercontent.com/u/367554?v=3","gravatar_id":"","url":"https://api.github.com/users/livarcocc","html_url":"https://github.com/livarcocc","followers_url":"https://api.github.com/users/livarcocc/followers","following_url":"https://api.github.com/users/livarcocc/following{/other_user}","gists_url":"https://api.github.com/users/livarcocc/gists{/gist_id}","starred_url":"https://api.github.com/users/livarcocc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/livarcocc/subscriptions","organizations_url":"https://api.github.com/users/livarcocc/orgs","repos_url":"https://api.github.com/users/livarcocc/repos","events_url":"https://api.github.com/users/livarcocc/events{/privacy}","received_events_url":"https://api.github.com/users/livarcocc/received_events","type":"User","site_admin":false},"body":"Shouldn't this be a parameter?","created_at":"2016-12-22T04:50:58Z","updated_at":"2016-12-22T04:50:58Z","html_url":"https://github.com/dotnet/cli/pull/5122#discussion_r93565793","pull_request_url":"https://api.github.com/repos/dotnet/cli/pulls/5122","_links":{"self":{"href":"https://api.github.com/repos/dotnet/cli/pulls/comments/93565793"},"html":{"href":"https://github.com/dotnet/cli/pull/5122#discussion_r93565793"},"pull_request":{"href":"https://api.github.com/repos/dotnet/cli/pulls/5122"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/cli/pulls/5122","id":98996389,"html_url":"https://github.com/dotnet/cli/pull/5122","diff_url":"https://github.com/dotnet/cli/pull/5122.diff","patch_url":"https://github.com/dotnet/cli/pull/5122.patch","issue_url":"https://api.github.com/repos/dotnet/cli/issues/5122","number":5122,"state":"open","locked":false,"title":"Adding dotnet add package sub command","user":{"login":"mishra14","id":10507120,"avatar_url":"https://avatars.githubusercontent.com/u/10507120?v=3","gravatar_id":"","url":"https://api.github.com/users/mishra14","html_url":"https://github.com/mishra14","followers_url":"https://api.github.com/users/mishra14/followers","following_url":"https://api.github.com/users/mishra14/following{/other_user}","gists_url":"https://api.github.com/users/mishra14/gists{/gist_id}","starred_url":"https://api.github.com/users/mishra14/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mishra14/subscriptions","organizations_url":"https://api.github.com/users/mishra14/orgs","repos_url":"https://api.github.com/users/mishra14/repos","events_url":"https://api.github.com/users/mishra14/events{/privacy}","received_events_url":"https://api.github.com/users/mishra14/received_events","type":"User","site_admin":false},"body":"Adding the `dotnet add package` sub command to add package references. \r\n\r\nNuGet part of the work : https://github.com/NuGet/NuGet.Client/pull/1063 \r\n\r\nFixes add package part of https://github.com/dotnet/cli/issues/4521 and https://github.com/NuGet/Home/issues/3751\r\n\r\n//cc: @livarcocc @piotrpMSFT @blackdwarf @krwq @rrelyea @emgarten ","created_at":"2016-12-21T20:07:31Z","updated_at":"2016-12-22T04:50:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"24ea5af5ac21b5f4748df14e72ed90de5968f4b1","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/cli/pulls/5122/commits","review_comments_url":"https://api.github.com/repos/dotnet/cli/pulls/5122/comments","review_comment_url":"https://api.github.com/repos/dotnet/cli/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/cli/issues/5122/comments","statuses_url":"https://api.github.com/repos/dotnet/cli/statuses/2738ea8a5a7101c80b301e73fe084206cea59339","head":{"label":"mishra14:dev-anmishr-dotnetaddpackage","ref":"dev-anmishr-dotnetaddpackage","sha":"2738ea8a5a7101c80b301e73fe084206cea59339","user":{"login":"mishra14","id":10507120,"avatar_url":"https://avatars.githubusercontent.com/u/10507120?v=3","gravatar_id":"","url":"https://api.github.com/users/mishra14","html_url":"https://github.com/mishra14","followers_url":"https://api.github.com/users/mishra14/followers","following_url":"https://api.github.com/users/mishra14/following{/other_user}","gists_url":"https://api.github.com/users/mishra14/gists{/gist_id}","starred_url":"https://api.github.com/users/mishra14/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mishra14/subscriptions","organizations_url":"https://api.github.com/users/mishra14/orgs","repos_url":"https://api.github.com/users/mishra14/repos","events_url":"https://api.github.com/users/mishra14/events{/privacy}","received_events_url":"https://api.github.com/users/mishra14/received_events","type":"User","site_admin":false},"repo":{"id":77001818,"name":"cli","full_name":"mishra14/cli","owner":{"login":"mishra14","id":10507120,"avatar_url":"https://avatars.githubusercontent.com/u/10507120?v=3","gravatar_id":"","url":"https://api.github.com/users/mishra14","html_url":"https://github.com/mishra14","followers_url":"https://api.github.com/users/mishra14/followers","following_url":"https://api.github.com/users/mishra14/following{/other_user}","gists_url":"https://api.github.com/users/mishra14/gists{/gist_id}","starred_url":"https://api.github.com/users/mishra14/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mishra14/subscriptions","organizations_url":"https://api.github.com/users/mishra14/orgs","repos_url":"https://api.github.com/users/mishra14/repos","events_url":"https://api.github.com/users/mishra14/events{/privacy}","received_events_url":"https://api.github.com/users/mishra14/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mishra14/cli","description":"This repo contains the .NET Core command-line (CLI) tools, used for building .NET Core apps and libraries through your development flow (compiling, NuGet package management, running, testing, ...).","fork":true,"url":"https://api.github.com/repos/mishra14/cli","forks_url":"https://api.github.com/repos/mishra14/cli/forks","keys_url":"https://api.github.com/repos/mishra14/cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mishra14/cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mishra14/cli/teams","hooks_url":"https://api.github.com/repos/mishra14/cli/hooks","issue_events_url":"https://api.github.com/repos/mishra14/cli/issues/events{/number}","events_url":"https://api.github.com/repos/mishra14/cli/events","assignees_url":"https://api.github.com/repos/mishra14/cli/assignees{/user}","branches_url":"https://api.github.com/repos/mishra14/cli/branches{/branch}","tags_url":"https://api.github.com/repos/mishra14/cli/tags","blobs_url":"https://api.github.com/repos/mishra14/cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mishra14/cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mishra14/cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/mishra14/cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mishra14/cli/statuses/{sha}","languages_url":"https://api.github.com/repos/mishra14/cli/languages","stargazers_url":"https://api.github.com/repos/mishra14/cli/stargazers","contributors_url":"https://api.github.com/repos/mishra14/cli/contributors","subscribers_url":"https://api.github.com/repos/mishra14/cli/subscribers","subscription_url":"https://api.github.com/repos/mishra14/cli/subscription","commits_url":"https://api.github.com/repos/mishra14/cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/mishra14/cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/mishra14/cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/mishra14/cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/mishra14/cli/contents/{+path}","compare_url":"https://api.github.com/repos/mishra14/cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mishra14/cli/merges","archive_url":"https://api.github.com/repos/mishra14/cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mishra14/cli/downloads","issues_url":"https://api.github.com/repos/mishra14/cli/issues{/number}","pulls_url":"https://api.github.com/repos/mishra14/cli/pulls{/number}","milestones_url":"https://api.github.com/repos/mishra14/cli/milestones{/number}","notifications_url":"https://api.github.com/repos/mishra14/cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mishra14/cli/labels{/name}","releases_url":"https://api.github.com/repos/mishra14/cli/releases{/id}","deployments_url":"https://api.github.com/repos/mishra14/cli/deployments","created_at":"2016-12-21T00:25:07Z","updated_at":"2016-12-21T00:25:13Z","pushed_at":"2016-12-22T02:08:24Z","git_url":"git://github.com/mishra14/cli.git","ssh_url":"git@github.com:mishra14/cli.git","clone_url":"https://github.com/mishra14/cli.git","svn_url":"https://github.com/mishra14/cli","homepage":"https://docs.microsoft.com/dotnet/","size":26227,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"rel/1.0.0"}},"base":{"label":"dotnet:rel/1.0.0","ref":"rel/1.0.0","sha":"b4ef34bc38370d85d9089582a9fba9cce00dae28","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":43568107,"name":"cli","full_name":"dotnet/cli","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/cli","description":"This repo contains the .NET Core command-line (CLI) tools, used for building .NET Core apps and libraries through your development flow (compiling, NuGet package management, running, testing, ...).","fork":false,"url":"https://api.github.com/repos/dotnet/cli","forks_url":"https://api.github.com/repos/dotnet/cli/forks","keys_url":"https://api.github.com/repos/dotnet/cli/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/cli/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/cli/teams","hooks_url":"https://api.github.com/repos/dotnet/cli/hooks","issue_events_url":"https://api.github.com/repos/dotnet/cli/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/cli/events","assignees_url":"https://api.github.com/repos/dotnet/cli/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/cli/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/cli/tags","blobs_url":"https://api.github.com/repos/dotnet/cli/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/cli/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/cli/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/cli/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/cli/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/cli/languages","stargazers_url":"https://api.github.com/repos/dotnet/cli/stargazers","contributors_url":"https://api.github.com/repos/dotnet/cli/contributors","subscribers_url":"https://api.github.com/repos/dotnet/cli/subscribers","subscription_url":"https://api.github.com/repos/dotnet/cli/subscription","commits_url":"https://api.github.com/repos/dotnet/cli/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/cli/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/cli/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/cli/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/cli/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/cli/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/cli/merges","archive_url":"https://api.github.com/repos/dotnet/cli/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/cli/downloads","issues_url":"https://api.github.com/repos/dotnet/cli/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/cli/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/cli/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/cli/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/cli/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/cli/releases{/id}","deployments_url":"https://api.github.com/repos/dotnet/cli/deployments","created_at":"2015-10-02T18:03:15Z","updated_at":"2016-12-21T18:34:36Z","pushed_at":"2016-12-22T03:30:42Z","git_url":"git://github.com/dotnet/cli.git","ssh_url":"git@github.com:dotnet/cli.git","clone_url":"https://github.com/dotnet/cli.git","svn_url":"https://github.com/dotnet/cli","homepage":"https://docs.microsoft.com/dotnet/","size":29992,"stargazers_count":1676,"watchers_count":1676,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":492,"mirror_url":null,"open_issues_count":530,"forks":492,"open_issues":530,"watchers":1676,"default_branch":"rel/1.0.0"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/cli/pulls/5122"},"html":{"href":"https://github.com/dotnet/cli/pull/5122"},"issue":{"href":"https://api.github.com/repos/dotnet/cli/issues/5122"},"comments":{"href":"https://api.github.com/repos/dotnet/cli/issues/5122/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/cli/pulls/5122/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/cli/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/cli/pulls/5122/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/cli/statuses/2738ea8a5a7101c80b301e73fe084206cea59339"}}}}
{"actor":{"display_login":"livarcocc"}}