{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/roslyn/pulls/comments/38770740","id":38770740,"diff_hunk":"@@ -0,0 +1,170 @@\n+﻿// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.\n+\n+extern alias WORKSPACES;\n+\n+using Newtonsoft.Json;\n+using Newtonsoft.Json.Linq;\n+using Roslyn.Utilities;\n+using System;\n+using System.Collections.Immutable;\n+using System.Diagnostics;\n+using System.IO;\n+using System.Reflection;\n+\n+namespace Microsoft.CodeAnalysis.Editor.Interactive\n+{\n+    internal sealed class NuGetPackageResolverImpl : WORKSPACES::Microsoft.CodeAnalysis.Scripting.NuGetPackageResolver\n+    {\n+        private readonly string _packagesDirectory;\n+\n+        internal NuGetPackageResolverImpl(string packagesDirectory)\n+        {\n+            Debug.Assert(PathUtilities.IsAbsolute(packagesDirectory));\n+            _packagesDirectory = packagesDirectory;\n+        }\n+\n+        internal override ImmutableArray<string> ResolveNuGetPackage(string reference)\n+        {\n+            string packageName;\n+            string packageVersion;\n+            if (!ParsePackageReference(reference, out packageName, out packageVersion))\n+            {\n+                return default(ImmutableArray<string>);\n+            }\n+\n+            var tempPath = PathUtilities.CombineAbsoluteAndRelativePaths(Path.GetTempPath(), Guid.NewGuid().ToString(\"D\"));\n+            var tempDir = Directory.CreateDirectory(tempPath);\n+            try\n+            {\n+                // Create project.json.\n+                var projectJson = PathUtilities.CombineAbsoluteAndRelativePaths(tempPath, \"project.json\");\n+                using (var stream = File.OpenWrite(projectJson))\n+                using (var writer = new StreamWriter(stream))\n+                {\n+                    WriteProjectJson(writer, packageName, packageVersion);\n+                }\n+\n+                // Run \"nuget.exe restore project.json\" to generate project.lock.json.\n+                NuGetRestore(projectJson);\n+\n+                // Read the references from project.lock.json.\n+                var projectLockJson = PathUtilities.CombineAbsoluteAndRelativePaths(tempPath, \"project.lock.json\");\n+                using (var stream = File.OpenRead(projectLockJson))\n+                using (var reader = new StreamReader(stream))\n+                {\n+                    return ReadProjectLockJson(_packagesDirectory, reader);\n+                }\n+            }\n+            finally\n+            {\n+                tempDir.Delete(recursive: true);\n+            }\n+        }\n+\n+        /// <summary>\n+        /// Syntax is \"id/version\", matching references in project.lock.json.\n+        /// </summary>\n+        internal static bool ParsePackageReference(string reference, out string name, out string version)\n+        {\n+            int separator = reference.IndexOf('/');\n+            int n = reference.Length;\n+            if ((separator > 0) &&\n+                (separator < n - 1) &&\n+                (reference.IndexOf('/', separator + 1) < 0))\n+            {\n+                name = reference.Substring(0, separator);\n+                version = reference.Substring(separator + 1);\n+                return true;\n+            }\n+            name = null;\n+            version = null;\n+            return false;\n+        }\n+\n+        /// <summary>\n+        /// Generate a project.json file with the packages as \"dependencies\".\n+        /// </summary>\n+        internal static void WriteProjectJson(TextWriter writer, string packageName, string packageVersion)\n+        {\n+            using (var jsonWriter = new JsonTextWriter(writer))\n+            {\n+                jsonWriter.Formatting = Newtonsoft.Json.Formatting.Indented;\n+                jsonWriter.WriteStartObject();\n+                jsonWriter.WritePropertyName(\"dependencies\");\n+                jsonWriter.WriteStartObject();\n+                jsonWriter.WritePropertyName(packageName, escape: true);\n+                jsonWriter.WriteValue(packageVersion);\n+                jsonWriter.WriteEndObject();\n+                jsonWriter.WriteEndObject();","path":"src/Interactive/EditorFeatures/Core/Extensibility/Interactive/NuGetPackageResolverImpl.cs","position":98,"original_position":98,"commit_id":"c7dfd3294574f52a668017738916a7b2bd365a88","original_commit_id":"c7dfd3294574f52a668017738916a7b2bd365a88","user":{"login":"KevinH-MS","id":6464209,"avatar_url":"https://avatars.githubusercontent.com/u/6464209?v=3","gravatar_id":"","url":"https://api.github.com/users/KevinH-MS","html_url":"https://github.com/KevinH-MS","followers_url":"https://api.github.com/users/KevinH-MS/followers","following_url":"https://api.github.com/users/KevinH-MS/following{/other_user}","gists_url":"https://api.github.com/users/KevinH-MS/gists{/gist_id}","starred_url":"https://api.github.com/users/KevinH-MS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/KevinH-MS/subscriptions","organizations_url":"https://api.github.com/users/KevinH-MS/orgs","repos_url":"https://api.github.com/users/KevinH-MS/repos","events_url":"https://api.github.com/users/KevinH-MS/events{/privacy}","received_events_url":"https://api.github.com/users/KevinH-MS/received_events","type":"User","site_admin":false},"body":"Should we have some logic for determining a reasonable \"framework\" as well?","created_at":"2015-09-04T16:47:03Z","updated_at":"2015-09-04T16:47:03Z","html_url":"https://github.com/dotnet/roslyn/pull/4975#discussion_r38770740","pull_request_url":"https://api.github.com/repos/dotnet/roslyn/pulls/4975","_links":{"self":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/comments/38770740"},"html":{"href":"https://github.com/dotnet/roslyn/pull/4975#discussion_r38770740"},"pull_request":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/4975"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/roslyn/pulls/4975","id":44133069,"html_url":"https://github.com/dotnet/roslyn/pull/4975","diff_url":"https://github.com/dotnet/roslyn/pull/4975.diff","patch_url":"https://github.com/dotnet/roslyn/pull/4975.patch","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/4975","number":4975,"state":"open","locked":false,"title":"Implement NuGetPackageResolver","user":{"login":"cston","id":10732005,"avatar_url":"https://avatars.githubusercontent.com/u/10732005?v=3","gravatar_id":"","url":"https://api.github.com/users/cston","html_url":"https://github.com/cston","followers_url":"https://api.github.com/users/cston/followers","following_url":"https://api.github.com/users/cston/following{/other_user}","gists_url":"https://api.github.com/users/cston/gists{/gist_id}","starred_url":"https://api.github.com/users/cston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cston/subscriptions","organizations_url":"https://api.github.com/users/cston/orgs","repos_url":"https://api.github.com/users/cston/repos","events_url":"https://api.github.com/users/cston/events{/privacy}","received_events_url":"https://api.github.com/users/cston/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-03T17:15:17Z","updated_at":"2015-09-04T16:47:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"827365a7dc64df725487a35f3cd36306b4c02394","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/roslyn/pulls/4975/commits","review_comments_url":"https://api.github.com/repos/dotnet/roslyn/pulls/4975/comments","review_comment_url":"https://api.github.com/repos/dotnet/roslyn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/4975/comments","statuses_url":"https://api.github.com/repos/dotnet/roslyn/statuses/c7dfd3294574f52a668017738916a7b2bd365a88","head":{"label":"cston:nuget","ref":"nuget","sha":"c7dfd3294574f52a668017738916a7b2bd365a88","user":{"login":"cston","id":10732005,"avatar_url":"https://avatars.githubusercontent.com/u/10732005?v=3","gravatar_id":"","url":"https://api.github.com/users/cston","html_url":"https://github.com/cston","followers_url":"https://api.github.com/users/cston/followers","following_url":"https://api.github.com/users/cston/following{/other_user}","gists_url":"https://api.github.com/users/cston/gists{/gist_id}","starred_url":"https://api.github.com/users/cston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cston/subscriptions","organizations_url":"https://api.github.com/users/cston/orgs","repos_url":"https://api.github.com/users/cston/repos","events_url":"https://api.github.com/users/cston/events{/privacy}","received_events_url":"https://api.github.com/users/cston/received_events","type":"User","site_admin":false},"repo":{"id":30556803,"name":"roslyn","full_name":"cston/roslyn","owner":{"login":"cston","id":10732005,"avatar_url":"https://avatars.githubusercontent.com/u/10732005?v=3","gravatar_id":"","url":"https://api.github.com/users/cston","html_url":"https://github.com/cston","followers_url":"https://api.github.com/users/cston/followers","following_url":"https://api.github.com/users/cston/following{/other_user}","gists_url":"https://api.github.com/users/cston/gists{/gist_id}","starred_url":"https://api.github.com/users/cston/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cston/subscriptions","organizations_url":"https://api.github.com/users/cston/orgs","repos_url":"https://api.github.com/users/cston/repos","events_url":"https://api.github.com/users/cston/events{/privacy}","received_events_url":"https://api.github.com/users/cston/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cston/roslyn","description":"The .NET Compiler Platform (\"Roslyn\") provides open-source C# and Visual Basic compilers with rich code analysis APIs.","fork":true,"url":"https://api.github.com/repos/cston/roslyn","forks_url":"https://api.github.com/repos/cston/roslyn/forks","keys_url":"https://api.github.com/repos/cston/roslyn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cston/roslyn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cston/roslyn/teams","hooks_url":"https://api.github.com/repos/cston/roslyn/hooks","issue_events_url":"https://api.github.com/repos/cston/roslyn/issues/events{/number}","events_url":"https://api.github.com/repos/cston/roslyn/events","assignees_url":"https://api.github.com/repos/cston/roslyn/assignees{/user}","branches_url":"https://api.github.com/repos/cston/roslyn/branches{/branch}","tags_url":"https://api.github.com/repos/cston/roslyn/tags","blobs_url":"https://api.github.com/repos/cston/roslyn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cston/roslyn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cston/roslyn/git/refs{/sha}","trees_url":"https://api.github.com/repos/cston/roslyn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cston/roslyn/statuses/{sha}","languages_url":"https://api.github.com/repos/cston/roslyn/languages","stargazers_url":"https://api.github.com/repos/cston/roslyn/stargazers","contributors_url":"https://api.github.com/repos/cston/roslyn/contributors","subscribers_url":"https://api.github.com/repos/cston/roslyn/subscribers","subscription_url":"https://api.github.com/repos/cston/roslyn/subscription","commits_url":"https://api.github.com/repos/cston/roslyn/commits{/sha}","git_commits_url":"https://api.github.com/repos/cston/roslyn/git/commits{/sha}","comments_url":"https://api.github.com/repos/cston/roslyn/comments{/number}","issue_comment_url":"https://api.github.com/repos/cston/roslyn/issues/comments{/number}","contents_url":"https://api.github.com/repos/cston/roslyn/contents/{+path}","compare_url":"https://api.github.com/repos/cston/roslyn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cston/roslyn/merges","archive_url":"https://api.github.com/repos/cston/roslyn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cston/roslyn/downloads","issues_url":"https://api.github.com/repos/cston/roslyn/issues{/number}","pulls_url":"https://api.github.com/repos/cston/roslyn/pulls{/number}","milestones_url":"https://api.github.com/repos/cston/roslyn/milestones{/number}","notifications_url":"https://api.github.com/repos/cston/roslyn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cston/roslyn/labels{/name}","releases_url":"https://api.github.com/repos/cston/roslyn/releases{/id}","created_at":"2015-02-09T20:26:55Z","updated_at":"2015-02-11T03:04:47Z","pushed_at":"2015-09-04T07:39:42Z","git_url":"git://github.com/cston/roslyn.git","ssh_url":"git@github.com:cston/roslyn.git","clone_url":"https://github.com/cston/roslyn.git","svn_url":"https://github.com/cston/roslyn","homepage":"","size":93399,"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":"master"}},"base":{"label":"dotnet:master","ref":"master","sha":"1fe1daae0c5676317a4ef2b1ca27384adeb61abc","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":29078997,"name":"roslyn","full_name":"dotnet/roslyn","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/roslyn","description":"The .NET Compiler Platform (\"Roslyn\") provides open-source C# and Visual Basic compilers with rich code analysis APIs.","fork":false,"url":"https://api.github.com/repos/dotnet/roslyn","forks_url":"https://api.github.com/repos/dotnet/roslyn/forks","keys_url":"https://api.github.com/repos/dotnet/roslyn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/roslyn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/roslyn/teams","hooks_url":"https://api.github.com/repos/dotnet/roslyn/hooks","issue_events_url":"https://api.github.com/repos/dotnet/roslyn/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/roslyn/events","assignees_url":"https://api.github.com/repos/dotnet/roslyn/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/roslyn/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/roslyn/tags","blobs_url":"https://api.github.com/repos/dotnet/roslyn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/roslyn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/roslyn/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/roslyn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/roslyn/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/roslyn/languages","stargazers_url":"https://api.github.com/repos/dotnet/roslyn/stargazers","contributors_url":"https://api.github.com/repos/dotnet/roslyn/contributors","subscribers_url":"https://api.github.com/repos/dotnet/roslyn/subscribers","subscription_url":"https://api.github.com/repos/dotnet/roslyn/subscription","commits_url":"https://api.github.com/repos/dotnet/roslyn/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/roslyn/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/roslyn/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/roslyn/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/roslyn/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/roslyn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/roslyn/merges","archive_url":"https://api.github.com/repos/dotnet/roslyn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/roslyn/downloads","issues_url":"https://api.github.com/repos/dotnet/roslyn/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/roslyn/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/roslyn/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/roslyn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/roslyn/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/roslyn/releases{/id}","created_at":"2015-01-11T02:39:03Z","updated_at":"2015-09-04T16:16:26Z","pushed_at":"2015-09-04T16:38:39Z","git_url":"git://github.com/dotnet/roslyn.git","ssh_url":"git@github.com:dotnet/roslyn.git","clone_url":"https://github.com/dotnet/roslyn.git","svn_url":"https://github.com/dotnet/roslyn","homepage":"","size":186037,"stargazers_count":3169,"watchers_count":3169,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":733,"mirror_url":null,"open_issues_count":1426,"forks":733,"open_issues":1426,"watchers":3169,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/4975"},"html":{"href":"https://github.com/dotnet/roslyn/pull/4975"},"issue":{"href":"https://api.github.com/repos/dotnet/roslyn/issues/4975"},"comments":{"href":"https://api.github.com/repos/dotnet/roslyn/issues/4975/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/4975/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/roslyn/pulls/4975/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/roslyn/statuses/c7dfd3294574f52a668017738916a7b2bd365a88"}}}}