예제 #1
0
        private static Process LaunchBuild(BuildInfo buildInfo, Action <string> stdOutHandler, Action <string> stdErrHandler)
        {
            (string msbuildPath, BuildTool buildTool) = MsBuildFinder.FindMsBuild();

            if (msbuildPath == null)
            {
                throw new FileNotFoundException("Cannot find the MSBuild executable.");
            }

            string compilerArgs = BuildArguments(buildTool, buildInfo);

            var startInfo = new ProcessStartInfo(msbuildPath, compilerArgs);

            string launchMessage = $"Running: \"{startInfo.FileName}\" {startInfo.Arguments}";

            stdOutHandler?.Invoke(launchMessage);
            if (Godot.OS.IsStdoutVerbose())
            {
                Console.WriteLine(launchMessage);
            }

            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;
            startInfo.UseShellExecute        = false;
            startInfo.CreateNoWindow         = true;

            if (UsingMonoMsBuildOnWindows)
            {
                // These environment variables are required for Mono's MSBuild to find the compilers.
                // We use the batch files in Mono's bin directory to make sure the compilers are executed with mono.
                string monoWinBinDir = MonoWindowsBinDir;
                startInfo.EnvironmentVariables.Add("CscToolExe", Path.Combine(monoWinBinDir, "csc.bat"));
                startInfo.EnvironmentVariables.Add("VbcToolExe", Path.Combine(monoWinBinDir, "vbc.bat"));
                startInfo.EnvironmentVariables.Add("FscToolExe", Path.Combine(monoWinBinDir, "fsharpc.bat"));
            }

            // Needed when running from Developer Command Prompt for VS
            RemovePlatformVariable(startInfo.EnvironmentVariables);

            var process = new Process {
                StartInfo = startInfo
            };

            if (stdOutHandler != null)
            {
                process.OutputDataReceived += (s, e) => stdOutHandler.Invoke(e.Data);
            }
            if (stdErrHandler != null)
            {
                process.ErrorDataReceived += (s, e) => stdErrHandler.Invoke(e.Data);
            }

            process.Start();

            process.BeginOutputReadLine();
            process.BeginErrorReadLine();

            return(process);
        }
예제 #2
0
        private static Process LaunchBuild(string solution, IEnumerable <string> targets, string config, string loggerOutputDir, IEnumerable <string> customProperties = null)
        {
            (string msbuildPath, BuildTool buildTool) = MsBuildFinder.FindMsBuild();

            if (msbuildPath == null)
            {
                throw new FileNotFoundException("Cannot find the MSBuild executable.");
            }

            var customPropertiesList = new List <string>();

            if (customProperties != null)
            {
                customPropertiesList.AddRange(customProperties);
            }

            string compilerArgs = BuildArguments(buildTool, solution, targets, config, loggerOutputDir, customPropertiesList);

            var startInfo = new ProcessStartInfo(msbuildPath, compilerArgs);

            bool redirectOutput = !IsDebugMsBuildRequested() && !PrintBuildOutput;

            if (!redirectOutput || Godot.OS.IsStdoutVerbose())
            {
                Console.WriteLine($"Running: \"{startInfo.FileName}\" {startInfo.Arguments}");
            }

            startInfo.RedirectStandardOutput = redirectOutput;
            startInfo.RedirectStandardError  = redirectOutput;
            startInfo.UseShellExecute        = false;

            if (UsingMonoMsBuildOnWindows)
            {
                // These environment variables are required for Mono's MSBuild to find the compilers.
                // We use the batch files in Mono's bin directory to make sure the compilers are executed with mono.
                string monoWinBinDir = MonoWindowsBinDir;
                startInfo.EnvironmentVariables.Add("CscToolExe", Path.Combine(monoWinBinDir, "csc.bat"));
                startInfo.EnvironmentVariables.Add("VbcToolExe", Path.Combine(monoWinBinDir, "vbc.bat"));
                startInfo.EnvironmentVariables.Add("FscToolExe", Path.Combine(monoWinBinDir, "fsharpc.bat"));
            }

            // Needed when running from Developer Command Prompt for VS
            RemovePlatformVariable(startInfo.EnvironmentVariables);

            var process = new Process {
                StartInfo = startInfo
            };

            process.Start();

            if (redirectOutput)
            {
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
            }

            return(process);
        }
예제 #3
0
        private static string GetMsBuildPath()
        {
            string msbuildPath = MsBuildFinder.FindMsBuild();

            if (msbuildPath == null)
            {
                throw new FileNotFoundException("Cannot find the MSBuild executable.");
            }

            return(msbuildPath);
        }