protected override int Execute() { var commands = _args.TakeWhile(a => a[0] != '-').ToList(); if (_help.HasValue() || ShouldHelp(commands)) { return(ShowHelp(_help.HasValue(), commands)); } var projectFile = FindProjects( _project.Value(), Resources.NoProject, Resources.MultipleProjects); Reporter.WriteVerbose(Resources.UsingProject(projectFile)); var starupProjectFile = FindProjects( _startupProject.Value(), Resources.NoStartupProject, Resources.MultipleStartupProjects); Reporter.WriteVerbose(Resources.UsingStartupProject(starupProjectFile)); var project = Project.FromFile(projectFile, _msbuildprojectextensionspath.Value()); var startupProject = Project.FromFile( starupProjectFile, _msbuildprojectextensionspath.Value(), _framework.Value(), _configuration.Value(), _runtime.Value()); if (!_noBuild.HasValue()) { startupProject.Build(); } string executable; var args = new List <string>(); var toolsPath = Path.Combine( Path.GetDirectoryName(typeof(Program).GetTypeInfo().Assembly.Location), "tools"); var targetDir = Path.GetFullPath(Path.Combine(startupProject.ProjectDir, startupProject.OutputPath)); var targetPath = Path.Combine(targetDir, project.TargetFileName); var startupTargetPath = Path.Combine(targetDir, startupProject.TargetFileName); var depsFile = Path.Combine( targetDir, startupProject.AssemblyName + ".deps.json"); var runtimeConfig = Path.Combine( targetDir, startupProject.AssemblyName + ".runtimeconfig.json"); var projectAssetsFile = startupProject.ProjectAssetsFile; var targetFramework = new FrameworkName(startupProject.TargetFrameworkMoniker); if (targetFramework.Identifier == ".NETFramework") { executable = Path.Combine( toolsPath, "net461", startupProject.PlatformTarget == "x86" ? "win-x86" : "any", "ef.exe"); } else if (targetFramework.Identifier == ".NETCoreApp") { executable = "dotnet"; args.Add("exec"); args.Add("--depsfile"); args.Add(depsFile); if (!string.IsNullOrEmpty(projectAssetsFile)) { using (var reader = new JsonTextReader(File.OpenText(projectAssetsFile))) { var projectAssets = JObject.ReadFrom(reader); var packageFolders = projectAssets["packageFolders"].Children <JProperty>().Select(p => p.Name); foreach (var packageFolder in packageFolders) { args.Add("--additionalprobingpath"); args.Add(packageFolder.TrimEnd(Path.DirectorySeparatorChar)); } } } if (File.Exists(runtimeConfig)) { args.Add("--runtimeconfig"); args.Add(runtimeConfig); } else if (startupProject.RuntimeFrameworkVersion.Length != 0) { args.Add("--fx-version"); args.Add(startupProject.RuntimeFrameworkVersion); } args.Add(Path.Combine(toolsPath, "netcoreapp2.0", "any", "ef.dll")); } else if (targetFramework.Identifier == ".NETStandard") { throw new CommandException(Resources.NETStandardStartupProject(startupProject.ProjectName)); } else { throw new CommandException( Resources.UnsupportedFramework(startupProject.ProjectName, targetFramework.Identifier)); } args.AddRange(_args); args.Add("--assembly"); args.Add(targetPath); args.Add("--startup-assembly"); args.Add(startupTargetPath); args.Add("--project-dir"); args.Add(project.ProjectDir); args.Add("--language"); args.Add(project.Language); if (Reporter.IsVerbose) { args.Add("--verbose"); } if (Reporter.NoColor) { args.Add("--no-color"); } if (Reporter.PrefixOutput) { args.Add("--prefix-output"); } if (project.RootNamespace.Length != 0) { args.Add("--root-namespace"); args.Add(project.RootNamespace); } return(Exe.Run(executable, args, startupProject.ProjectDir)); }