Example #1
0
        private static void Dispatch(string[] args)
        {
            var projectFile      = ProjectReader.GetProject(string.Empty);
            var targetFrameworks = projectFile
                                   .GetTargetFrameworks()
                                   .Select(frameworkInformation => frameworkInformation.FrameworkName);
            var framework = default(NuGetFramework);

            if (!TryResolveFramework(targetFrameworks, out framework))
            {
                return;
            }

            // Let's build the project first.
            var buildCommand = BuildCommandFactory.Create(
                projectFile.ProjectFilePath,
                "Debug",
                framework,
                null,
                null);
            var buildExitCode = buildCommand
                                .ForwardStdErr()
                                .ForwardStdOut()
                                .Execute()
                                .ExitCode;

            if (buildExitCode != 0)
            {
                throw new Exception($"Building {projectFile.Name} failed...");
            }
            Console.WriteLine();

            var dispatchCommand = DotnetToolDispatcher.CreateDispatchCommand(
                args,
                framework,
                "Debug",
                outputPath: null,
                buildBasePath: null,
                projectDirectory: projectFile.ProjectDirectory);

            using (var errorWriter = new StringWriter())
            {
                var commandExitCode = dispatchCommand
                                      .ForwardStdErr(errorWriter)
                                      .ForwardStdOut()
                                      .Execute()
                                      .ExitCode;

                if (commandExitCode != 0)
                {
                    Console.WriteLine(errorWriter.ToString());
                }

                return;
            }
        }
Example #2
0
        private static void Dispatch(string[] args)
        {
            var projectFile      = ProjectReader.GetProject(string.Empty);
            var targetFrameworks = projectFile.TargetFrameworks;

            if (!TryResolveFramework(targetFrameworks, out var framework))
            {
                return;
            }

            // Let's build the project first.
            var buildCommand = BuildCommandFactory.Create(
                projectFile.ProjectFilePath,
                "Debug",
                framework.Framework,
                null,
                null);
            var buildExitCode = buildCommand
                                .ForwardStdErr()
                                .ForwardStdOut()
                                .Execute()
                                .ExitCode;

            if (buildExitCode != 0)
            {
                throw new Exception($"Building {projectFile.Name} failed...");
            }
            Console.WriteLine();

            var runtime      = GetRuntimeOption(args) ?? string.Empty;
            var toolPath     = Path.Combine(projectFile.ProjectDirectory, "bin", "Debug", framework.TFM, runtime, "dotnet-ef.exe");
            var assemblyPath = Path.Combine(projectFile.ProjectDirectory, "bin", "Debug", framework.TFM, runtime, projectFile.Name + ".exe");

            var dispatchCommand = DotnetToolDispatcher.CreateDispatchCommand(
                toolPath,
                args,
                framework.Framework,
                "Debug",
                assemblyPath);

            using (var errorWriter = new StringWriter())
            {
                var commandExitCode = dispatchCommand
                                      .ForwardStdErr(errorWriter)
                                      .ForwardStdOut()
                                      .Execute()
                                      .ExitCode;

                if (commandExitCode != 0)
                {
                    Console.WriteLine(errorWriter.ToString());
                }

                return;
            }
        }