Exemple #1
0
        public static bool Execute(ProjectProperties properties, Log log)
        {
            Console.WriteLine("compiling");
            var processSettings = new ProcessStartInfo
            {
                FileName = properties.CscPath,
                Arguments = properties.FormatCscArguments()
            };

            log.WriteLine("Executing {0}", processSettings.FileName);
            log.WriteLine("Csc Arguments: {0}", processSettings.Arguments);

            processSettings.CreateNoWindow = true;
            processSettings.RedirectStandardOutput = true;
            processSettings.UseShellExecute = false;

            Process cscProcess;
            try
            {
                cscProcess = Process.Start(processSettings);
            }
            catch (Win32Exception)
            {
                Console.WriteLine("ERROR: csc.exe needs to be on the path.");
                return false;
            }

            if (cscProcess == null) return false;
            var output = cscProcess.StandardOutput.ReadToEnd();
            log.WriteLine(output);

            cscProcess.WaitForExit();

            return !output.Contains("error CS");
        }
Exemple #2
0
        private static void Build(Settings settings, Log log)
        {
            var properties = ProjectPropertiesHelpers.InitializeProperties(settings, log);

            if (properties.Sources.Count == 0)
            {
                Console.WriteLine("no sources found");
                return;
            }

            if (!Directory.Exists(properties.OutputDirectory))
            {
                Directory.CreateDirectory(properties.OutputDirectory);
            }

            if (!Directory.Exists(properties.ToolsDirectory))
            {
                Directory.CreateDirectory(properties.ToolsDirectory);
            }

            if (!Directory.Exists(properties.PackagesDirectory))
            {
                Directory.CreateDirectory(properties.PackagesDirectory);
            }

            if (!NugetAction.GetNugetAndRestore(properties, log))
            {
                return;
            }

            if (!GetDependencies(properties, log))
            {
                log.WriteLine("Unable to get dependencies from the project.lock.json file.");
            }

            if (!CscAction.Execute(properties, Log)) return;
            if (Settings.Target != "library")
            {
                ConvertToCoreConsoleAction(properties);
            }
            OutputRuntimeDependenciesAction(properties, log);
            Console.WriteLine("bin\\{0} created", properties.AssemblyNameAndExtension);
        }
Exemple #3
0
        public static bool RestorePackagesAction(ProjectProperties properties, Log log, string nugetFile, string jsonFile, string nugetConfig)
        {
            Console.WriteLine("restoring packages");

            if (!File.Exists(nugetFile))
            {
                Console.WriteLine("Could not find file {0}.", nugetFile);
                return false;
            }

            if (!File.Exists(jsonFile))
            {
                Console.WriteLine("Could not find file {0}.", jsonFile);
                return false;
            }

            var processSettings = new ProcessStartInfo
            {
                FileName = nugetFile,
                Arguments = "restore " + jsonFile + " -PackagesDirectory " + properties.PackagesDirectory + " -ConfigFile " + nugetConfig,
                CreateNoWindow = true,
                UseShellExecute = false,
                RedirectStandardOutput = true,
                RedirectStandardError = true
            };

            log.WriteLine("Executing {0}", processSettings.FileName);
            log.WriteLine("Arguments: {0}", processSettings.Arguments);
            log.WriteLine("project.json:\n{0}", File.ReadAllText(jsonFile));

            using (var process = Process.Start(processSettings))
            {
                try
                {
                    if (process != null)
                    {
                        var output = process.StandardOutput.ReadToEnd();
                        var error = process.StandardError.ReadToEnd();
                        log.WriteLine(output);
                        log.Error(error);
                        process.WaitForExit();
                        var exitCode = process.ExitCode;
                        if (exitCode != 0) Console.WriteLine("Process exit code: {0}", exitCode);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return false;
                }
            }
            return true;
        }