{"action":"created","comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments/60815468","id":60815468,"diff_hunk":"@@ -0,0 +1,218 @@\n+﻿// Copyright (c) .NET Foundation. All rights reserved.\n+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.\n+\n+\n+using System;\n+using System.Collections;\n+using System.Collections.Generic;\n+using System.IO;\n+using System.Linq;\n+using System.Reflection;\n+using JetBrains.Annotations;\n+using Microsoft.DotNet.Cli.Utils;\n+using Microsoft.DotNet.ProjectModel;\n+using Microsoft.Extensions.PlatformAbstractions;\n+using NuGet.Frameworks;\n+using Microsoft.EntityFrameworkCore.Design;\n+using Microsoft.EntityFrameworkCore.Internal;\n+using Microsoft.EntityFrameworkCore.Migrations.Design;\n+using System.Threading;\n+using System.Threading.Tasks;\n+using Microsoft.EntityFrameworkCore.Scaffolding.Internal;\n+using Microsoft.EntityFrameworkCore.Design.Internal;\n+\n+namespace Microsoft.EntityFrameworkCore.Tools.Cli\n+{\n+    public class OperationExecutor\n+    {\n+        private const string DataDirEnvName = \"ADONET_DATA_DIR\";\n+\n+        private readonly LazyRef<MigrationsOperations> _migrationsOperations;\n+        private readonly LazyRef<DatabaseOperations> _databaseOperations;\n+        private readonly LazyRef<DbContextOperations> _contextOperations;\n+\n+        public OperationExecutor([CanBeNull] string startupProject, [CanBeNull] string environment)\n+        {\n+            var project = Path.Combine(Directory.GetCurrentDirectory(), Project.FileName);\n+            var buildStartup = true;\n+            if (startupProject == null)\n+            {\n+                startupProject = project;\n+                buildStartup = false;\n+            }\n+            // TODO flow through from dispatch\n+            var projectConfiguration = Constants.DefaultConfiguration;\n+            var projectFramework = FrameworkConstants.CommonFrameworks.NetCoreApp10;\n+\n+            // TODO flow through from dispatch\n+            var startupConfiguration = Constants.DefaultConfiguration;\n+            string startupBuildBaseDir = null;\n+            string startupOutputDir = null;\n+\n+            var startupProjectContext = GetCompatibleStartupProjectContext(startupProject);\n+\n+            var startupFramework = startupProjectContext.TargetFramework;\n+\n+            if (buildStartup)\n+            {\n+                Reporter.Verbose.WriteLine(\"Build started...\".Bold().Black());\n+\n+                var buildExitCode = BuildCommandFactory.Create(startupProject,\n+                        startupConfiguration,\n+                        startupFramework,\n+                        startupBuildBaseDir,\n+                        startupOutputDir)\n+                    .ForwardStdOut()\n+                    .ForwardStdErr()\n+                    .Execute()\n+                    .ExitCode;\n+\n+                if (buildExitCode != 0)\n+                {\n+                    throw new OperationException(\"Build failed.\");\n+                }\n+\n+                Reporter.Verbose.WriteLine(\"Build succeeded.\".Bold().Black());\n+            }\n+\n+            var runtimeOutputPath = startupProjectContext.GetOutputPaths(startupConfiguration)?.RuntimeOutputPath;\n+            if (!string.IsNullOrEmpty(runtimeOutputPath))\n+            {\n+                Environment.SetEnvironmentVariable(DataDirEnvName, runtimeOutputPath);\n+#if NET451\n+                AppDomain.CurrentDomain.SetData(\"DataDirectory\", runtimeOutputPath);\n+#endif\n+            }\n+\n+            var projectFile = ProjectReader.GetProject(project);","path":"src/Microsoft.EntityFrameworkCore.Tools.Cli/OperationExecutor.cs","position":87,"original_position":87,"commit_id":"07a640cdf88cc26b5f1e97a5fd6c890601a476aa","original_commit_id":"07a640cdf88cc26b5f1e97a5fd6c890601a476aa","user":{"login":"NTaylorMullen","id":2008729,"avatar_url":"https://avatars.githubusercontent.com/u/2008729?v=3","gravatar_id":"","url":"https://api.github.com/users/NTaylorMullen","html_url":"https://github.com/NTaylorMullen","followers_url":"https://api.github.com/users/NTaylorMullen/followers","following_url":"https://api.github.com/users/NTaylorMullen/following{/other_user}","gists_url":"https://api.github.com/users/NTaylorMullen/gists{/gist_id}","starred_url":"https://api.github.com/users/NTaylorMullen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NTaylorMullen/subscriptions","organizations_url":"https://api.github.com/users/NTaylorMullen/orgs","repos_url":"https://api.github.com/users/NTaylorMullen/repos","events_url":"https://api.github.com/users/NTaylorMullen/events{/privacy}","received_events_url":"https://api.github.com/users/NTaylorMullen/received_events","type":"User","site_admin":false},"body":"Why does this and the startupProject bits potentially fork?","created_at":"2016-04-22T23:28:18Z","updated_at":"2016-04-22T23:28:18Z","html_url":"https://github.com/aspnet/EntityFramework/pull/5142#discussion_r60815468","pull_request_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/5142","_links":{"self":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments/60815468"},"html":{"href":"https://github.com/aspnet/EntityFramework/pull/5142#discussion_r60815468"},"pull_request":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/5142"}}},"pull_request":{"url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/5142","id":67418438,"html_url":"https://github.com/aspnet/EntityFramework/pull/5142","diff_url":"https://github.com/aspnet/EntityFramework/pull/5142.diff","patch_url":"https://github.com/aspnet/EntityFramework/pull/5142.patch","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5142","number":5142,"state":"open","locked":false,"title":"[wip] Refactor design-time tools","user":{"login":"natemcmaster","id":2696087,"avatar_url":"https://avatars.githubusercontent.com/u/2696087?v=3","gravatar_id":"","url":"https://api.github.com/users/natemcmaster","html_url":"https://github.com/natemcmaster","followers_url":"https://api.github.com/users/natemcmaster/followers","following_url":"https://api.github.com/users/natemcmaster/following{/other_user}","gists_url":"https://api.github.com/users/natemcmaster/gists{/gist_id}","starred_url":"https://api.github.com/users/natemcmaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natemcmaster/subscriptions","organizations_url":"https://api.github.com/users/natemcmaster/orgs","repos_url":"https://api.github.com/users/natemcmaster/repos","events_url":"https://api.github.com/users/natemcmaster/events{/privacy}","received_events_url":"https://api.github.com/users/natemcmaster/received_events","type":"User","site_admin":false},"body":"Split design-time tools into three packages so that users need only install \"Microsoft.EntityFrameworkCore.Tools\" and nuget will restore the tools they need for the platform they target.\r\n\r\nThe packages:\r\n\r\n - **.Tools**\r\n     - A pseudo-metapackage. This contains shims to call into shared\r\n       components.\r\n     - **lib/net451/Microsoft.EntityFrameworkCore.Tools.dll** - Contains\r\n       PowerShell cmdlets and APIs that bridge it with common components.\r\n     - **lib/netcoreapp1.0/dotnet-ef.dll** - a light shim for initializing\r\n       commands on DotNet project. This executes from \"tools\".\r\n     - **lib/netcore50/Microsoft.EntityFrameworkCore.Tools.dll** - same as\r\n       net451. For compatibility with UWP only. This is never actually\r\n       executed.\r\n     - **build/netcore50/*.target** - swaps netcore50 to net451 at build time\r\n       on UWP projects\r\n     - **tools/*** - the powershell cmdlets\r\n - **.Tools.Cli**\r\n     - A program to launch commands from dotnet-cli. These execute as a\r\n       \"dependency\".\r\n     - **lib/netstandard1.5/*.dll** - Contains the entry point for executing\r\n       commands on a DotNet project model that supports .NET Core\r\n     - **lib/net451/*.exe** - Contains the entry point for executing commands\r\n       on a DotNet project modle that supports desktop .NET only\r\n - **.Tools.Core**\r\n     - contains shared components. This contains the implementation\r\n       details of executing commands.\r\n\r\nResolves https://github.com/aspnet/EntityFramework/issues/4577\r\nResolves https://github.com/aspnet/EntityFramework/issues/5065\r\nPartial fix for https://github.com/aspnet/EntityFramework/issues/3925\r\n\r\n## WIP - remaining work\r\n### Functional issues\r\n\r\n- [x] Can't use dotnet-ef in a class library or standalone apps. This dies with \"Could not resolve coreclr path\". https://github.com/dotnet/cli/issues/2645\r\n- [ ] There are issues loading assemblies when startup project and current project are different. Haven't identified the source of the issue.\r\n- [ ] Cannot install into a csproj. Blocked on https://github.com/NuGet/Home/issues/2635.\r\n- [ ] The framework/configuration on the dispatcher (dotnet-ef) should flow through to the \"inside-man\".\r\n\r\n### Cleanup\r\n\r\n- [ ] Put all strings into resx files\r\n- [ ] Enable functional tests to run on CI. Currently skipped due to flakiness. Ideally this will be cleaner when https://github.com/NuGet/Home/issues/2469 is supported.\r\n- [ ] Remove workaround that runs `dotnet restore --infer-runtimes` on the tools projects. Without this, dotnet-pack fails, complaining that no runtimes were specified.\r\n- [ ] Merge https://github.com/aspnet/Coherence/pull/79\r\n \r\ncc @divega @NTaylorMullen @bricelam ","created_at":"2016-04-21T20:38:36Z","updated_at":"2016-04-22T23:28:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f6fbc403076dab2ab0234e137a5856c13289c543","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/5142/commits","review_comments_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/5142/comments","review_comment_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments{/number}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5142/comments","statuses_url":"https://api.github.com/repos/aspnet/EntityFramework/statuses/07a640cdf88cc26b5f1e97a5fd6c890601a476aa","head":{"label":"natemcmaster:tools","ref":"tools","sha":"07a640cdf88cc26b5f1e97a5fd6c890601a476aa","user":{"login":"natemcmaster","id":2696087,"avatar_url":"https://avatars.githubusercontent.com/u/2696087?v=3","gravatar_id":"","url":"https://api.github.com/users/natemcmaster","html_url":"https://github.com/natemcmaster","followers_url":"https://api.github.com/users/natemcmaster/followers","following_url":"https://api.github.com/users/natemcmaster/following{/other_user}","gists_url":"https://api.github.com/users/natemcmaster/gists{/gist_id}","starred_url":"https://api.github.com/users/natemcmaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natemcmaster/subscriptions","organizations_url":"https://api.github.com/users/natemcmaster/orgs","repos_url":"https://api.github.com/users/natemcmaster/repos","events_url":"https://api.github.com/users/natemcmaster/events{/privacy}","received_events_url":"https://api.github.com/users/natemcmaster/received_events","type":"User","site_admin":false},"repo":{"id":19757095,"name":"EntityFramework","full_name":"natemcmaster/EntityFramework","owner":{"login":"natemcmaster","id":2696087,"avatar_url":"https://avatars.githubusercontent.com/u/2696087?v=3","gravatar_id":"","url":"https://api.github.com/users/natemcmaster","html_url":"https://github.com/natemcmaster","followers_url":"https://api.github.com/users/natemcmaster/followers","following_url":"https://api.github.com/users/natemcmaster/following{/other_user}","gists_url":"https://api.github.com/users/natemcmaster/gists{/gist_id}","starred_url":"https://api.github.com/users/natemcmaster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natemcmaster/subscriptions","organizations_url":"https://api.github.com/users/natemcmaster/orgs","repos_url":"https://api.github.com/users/natemcmaster/repos","events_url":"https://api.github.com/users/natemcmaster/events{/privacy}","received_events_url":"https://api.github.com/users/natemcmaster/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/natemcmaster/EntityFramework","description":"","fork":true,"url":"https://api.github.com/repos/natemcmaster/EntityFramework","forks_url":"https://api.github.com/repos/natemcmaster/EntityFramework/forks","keys_url":"https://api.github.com/repos/natemcmaster/EntityFramework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/natemcmaster/EntityFramework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/natemcmaster/EntityFramework/teams","hooks_url":"https://api.github.com/repos/natemcmaster/EntityFramework/hooks","issue_events_url":"https://api.github.com/repos/natemcmaster/EntityFramework/issues/events{/number}","events_url":"https://api.github.com/repos/natemcmaster/EntityFramework/events","assignees_url":"https://api.github.com/repos/natemcmaster/EntityFramework/assignees{/user}","branches_url":"https://api.github.com/repos/natemcmaster/EntityFramework/branches{/branch}","tags_url":"https://api.github.com/repos/natemcmaster/EntityFramework/tags","blobs_url":"https://api.github.com/repos/natemcmaster/EntityFramework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/natemcmaster/EntityFramework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/natemcmaster/EntityFramework/git/refs{/sha}","trees_url":"https://api.github.com/repos/natemcmaster/EntityFramework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/natemcmaster/EntityFramework/statuses/{sha}","languages_url":"https://api.github.com/repos/natemcmaster/EntityFramework/languages","stargazers_url":"https://api.github.com/repos/natemcmaster/EntityFramework/stargazers","contributors_url":"https://api.github.com/repos/natemcmaster/EntityFramework/contributors","subscribers_url":"https://api.github.com/repos/natemcmaster/EntityFramework/subscribers","subscription_url":"https://api.github.com/repos/natemcmaster/EntityFramework/subscription","commits_url":"https://api.github.com/repos/natemcmaster/EntityFramework/commits{/sha}","git_commits_url":"https://api.github.com/repos/natemcmaster/EntityFramework/git/commits{/sha}","comments_url":"https://api.github.com/repos/natemcmaster/EntityFramework/comments{/number}","issue_comment_url":"https://api.github.com/repos/natemcmaster/EntityFramework/issues/comments{/number}","contents_url":"https://api.github.com/repos/natemcmaster/EntityFramework/contents/{+path}","compare_url":"https://api.github.com/repos/natemcmaster/EntityFramework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/natemcmaster/EntityFramework/merges","archive_url":"https://api.github.com/repos/natemcmaster/EntityFramework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/natemcmaster/EntityFramework/downloads","issues_url":"https://api.github.com/repos/natemcmaster/EntityFramework/issues{/number}","pulls_url":"https://api.github.com/repos/natemcmaster/EntityFramework/pulls{/number}","milestones_url":"https://api.github.com/repos/natemcmaster/EntityFramework/milestones{/number}","notifications_url":"https://api.github.com/repos/natemcmaster/EntityFramework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/natemcmaster/EntityFramework/labels{/name}","releases_url":"https://api.github.com/repos/natemcmaster/EntityFramework/releases{/id}","deployments_url":"https://api.github.com/repos/natemcmaster/EntityFramework/deployments","created_at":"2014-05-13T21:47:53Z","updated_at":"2016-01-15T13:05:45Z","pushed_at":"2016-04-21T20:31:26Z","git_url":"git://github.com/natemcmaster/EntityFramework.git","ssh_url":"git@github.com:natemcmaster/EntityFramework.git","clone_url":"https://github.com/natemcmaster/EntityFramework.git","svn_url":"https://github.com/natemcmaster/EntityFramework","homepage":null,"size":33928,"stargazers_count":1,"watchers_count":1,"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":1,"default_branch":"dev"}},"base":{"label":"aspnet:release","ref":"release","sha":"809139d6748c837a2ad8e1b0f0a363406725c6d7","user":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"repo":{"id":16157746,"name":"EntityFramework","full_name":"aspnet/EntityFramework","owner":{"login":"aspnet","id":6476660,"avatar_url":"https://avatars.githubusercontent.com/u/6476660?v=3","gravatar_id":"","url":"https://api.github.com/users/aspnet","html_url":"https://github.com/aspnet","followers_url":"https://api.github.com/users/aspnet/followers","following_url":"https://api.github.com/users/aspnet/following{/other_user}","gists_url":"https://api.github.com/users/aspnet/gists{/gist_id}","starred_url":"https://api.github.com/users/aspnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aspnet/subscriptions","organizations_url":"https://api.github.com/users/aspnet/orgs","repos_url":"https://api.github.com/users/aspnet/repos","events_url":"https://api.github.com/users/aspnet/events{/privacy}","received_events_url":"https://api.github.com/users/aspnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/aspnet/EntityFramework","description":"Microsoft's recommended data access technology for new applications in .NET.","fork":false,"url":"https://api.github.com/repos/aspnet/EntityFramework","forks_url":"https://api.github.com/repos/aspnet/EntityFramework/forks","keys_url":"https://api.github.com/repos/aspnet/EntityFramework/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aspnet/EntityFramework/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aspnet/EntityFramework/teams","hooks_url":"https://api.github.com/repos/aspnet/EntityFramework/hooks","issue_events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/events{/number}","events_url":"https://api.github.com/repos/aspnet/EntityFramework/events","assignees_url":"https://api.github.com/repos/aspnet/EntityFramework/assignees{/user}","branches_url":"https://api.github.com/repos/aspnet/EntityFramework/branches{/branch}","tags_url":"https://api.github.com/repos/aspnet/EntityFramework/tags","blobs_url":"https://api.github.com/repos/aspnet/EntityFramework/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aspnet/EntityFramework/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aspnet/EntityFramework/git/refs{/sha}","trees_url":"https://api.github.com/repos/aspnet/EntityFramework/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aspnet/EntityFramework/statuses/{sha}","languages_url":"https://api.github.com/repos/aspnet/EntityFramework/languages","stargazers_url":"https://api.github.com/repos/aspnet/EntityFramework/stargazers","contributors_url":"https://api.github.com/repos/aspnet/EntityFramework/contributors","subscribers_url":"https://api.github.com/repos/aspnet/EntityFramework/subscribers","subscription_url":"https://api.github.com/repos/aspnet/EntityFramework/subscription","commits_url":"https://api.github.com/repos/aspnet/EntityFramework/commits{/sha}","git_commits_url":"https://api.github.com/repos/aspnet/EntityFramework/git/commits{/sha}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/comments{/number}","issue_comment_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments{/number}","contents_url":"https://api.github.com/repos/aspnet/EntityFramework/contents/{+path}","compare_url":"https://api.github.com/repos/aspnet/EntityFramework/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aspnet/EntityFramework/merges","archive_url":"https://api.github.com/repos/aspnet/EntityFramework/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aspnet/EntityFramework/downloads","issues_url":"https://api.github.com/repos/aspnet/EntityFramework/issues{/number}","pulls_url":"https://api.github.com/repos/aspnet/EntityFramework/pulls{/number}","milestones_url":"https://api.github.com/repos/aspnet/EntityFramework/milestones{/number}","notifications_url":"https://api.github.com/repos/aspnet/EntityFramework/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/labels{/name}","releases_url":"https://api.github.com/repos/aspnet/EntityFramework/releases{/id}","deployments_url":"https://api.github.com/repos/aspnet/EntityFramework/deployments","created_at":"2014-01-23T00:52:01Z","updated_at":"2016-04-22T12:13:23Z","pushed_at":"2016-04-22T22:49:39Z","git_url":"git://github.com/aspnet/EntityFramework.git","ssh_url":"git@github.com:aspnet/EntityFramework.git","clone_url":"https://github.com/aspnet/EntityFramework.git","svn_url":"https://github.com/aspnet/EntityFramework","homepage":"","size":49703,"stargazers_count":3160,"watchers_count":3160,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":967,"mirror_url":null,"open_issues_count":558,"forks":967,"open_issues":558,"watchers":3160,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/5142"},"html":{"href":"https://github.com/aspnet/EntityFramework/pull/5142"},"issue":{"href":"https://api.github.com/repos/aspnet/EntityFramework/issues/5142"},"comments":{"href":"https://api.github.com/repos/aspnet/EntityFramework/issues/5142/comments"},"review_comments":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/5142/comments"},"review_comment":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/aspnet/EntityFramework/pulls/5142/commits"},"statuses":{"href":"https://api.github.com/repos/aspnet/EntityFramework/statuses/07a640cdf88cc26b5f1e97a5fd6c890601a476aa"}}}}