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.GetFullPath( Path.Combine(Path.GetDirectoryName(typeof(Program).GetTypeInfo().Assembly.Location), "..", "..")); 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" ? "ef.x86.exe" : "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", "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)); }
protected override int Execute(string[] _) { var commands = _args !.TakeWhile(a => a[0] != '-').ToList(); if (_help !.HasValue() || ShouldHelp(commands)) { return(ShowHelp(_help.HasValue(), commands)); } var(projectFile, startupProjectFile) = ResolveProjects( _project !.Value(), _startupProject !.Value()); Reporter.WriteVerbose(Resources.UsingProject(projectFile)); Reporter.WriteVerbose(Resources.UsingStartupProject(startupProjectFile)); var project = Project.FromFile(projectFile, _msbuildprojectextensionspath !.Value()); var startupProject = Project.FromFile( startupProjectFile, _msbuildprojectextensionspath.Value(), _framework !.Value(), _configuration !.Value(), _runtime !.Value()); if (!_noBuild !.HasValue()) { Reporter.WriteInformation(Resources.BuildStarted); startupProject.Build(); Reporter.WriteInformation(Resources.BuildSucceeded); } string executable; var args = new List <string>(); var toolsPath = Path.Combine( Path.GetDirectoryName(typeof(Program).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") { if (targetFramework.Version < new Version(2, 0)) { throw new CommandException( Resources.NETCoreApp1StartupProject(startupProject.ProjectName, targetFramework.Version)); } executable = "dotnet"; args.Add("exec"); args.Add("--depsfile"); args.Add(depsFile); if (!string.IsNullOrEmpty(projectAssetsFile)) { using var file = File.OpenRead(projectAssetsFile); using var reader = JsonDocument.Parse(file); var projectAssets = reader.RootElement; var packageFolders = projectAssets.GetProperty("packageFolders").EnumerateObject().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("--project"); args.Add(projectFile); args.Add("--startup-assembly"); args.Add(startupTargetPath); args.Add("--startup-project"); args.Add(startupProjectFile); args.Add("--project-dir"); args.Add(project.ProjectDir !); args.Add("--root-namespace"); args.Add(project.RootNamespace !); args.Add("--language"); args.Add(project.Language !); if (string.Equals(project.Nullable, "enable", StringComparison.OrdinalIgnoreCase) || string.Equals(project.Nullable, "annotations", StringComparison.OrdinalIgnoreCase)) { args.Add("--nullable"); } args.Add("--working-dir"); args.Add(Directory.GetCurrentDirectory()); if (Reporter.IsVerbose) { args.Add("--verbose"); } if (Reporter.NoColor) { args.Add("--no-color"); } if (Reporter.PrefixOutput) { args.Add("--prefix-output"); } if (_applicationArgs !.Any()) { args.Add("--"); args.AddRange(_applicationArgs !); } return(Exe.Run(executable, args, startupProject.ProjectDir)); }