Beispiel #1
0
        public static int CopyProjectOutput(Project[] projects, string buildconfig, string outputpath, string[] includeProjects,
            string[] excludeProjects, bool deletetargetfolder, bool gatherall, bool simulate, bool verbose)
        {
            int result = 0;

            // If a project is excluded, it should not prevent referred projects from being included.

            List<Project> projects2 = projects.ToList();

            projects2 = ExcludeCorruptProjects(projects2, verbose);
            projects2 = ExcludeExplicitProjects(projects2, excludeProjects, verbose);
            projects2 = ExcludeReferredProjects(projects2, gatherall, includeProjects, verbose);
            projects2 = ExcludeWebMvcProjects(projects2, verbose);

            Console.WriteLine("Retrieving output folders for " + projects2.Count() + " projects.");

            var operations = projects2
                .Select(p =>
                    new
                    {
                        sourcepath = p.GetOutputFolder(buildconfig, verbose),
                        targetpath = Path.Combine(outputpath, FileHelper.GetCleanFolderName(Path.GetFileNameWithoutExtension(p._path)))
                    })
                .Where(p => p.sourcepath != null)
                .ToArray();

            if (deletetargetfolder && Directory.Exists(outputpath))
            {
                Console.WriteLine("Deleting folder: '" + outputpath + "'");
                Directory.Delete(outputpath, true);
            }

            Console.WriteLine("Copying " + operations.Length + " projects.");

            int copiedFiles = 0;

            foreach (var operation in operations)
            {
                string sourcepath = operation.sourcepath;
                string targetpath = operation.targetpath;

                ConsoleHelper.ColorWriteLine(ConsoleColor.Cyan, "Copying folder: '" + sourcepath + "' -> '" + targetpath + "'");

                if (!FileHelper.CopyFolder(new DirectoryInfo(sourcepath), new DirectoryInfo(targetpath), simulate, verbose, ref copiedFiles))
                {
                    result = 1;
                }
            }

            Console.WriteLine("Copied " + copiedFiles + " files.");

            return result;
        }
Beispiel #2
0
        public static Project LoadProject(string filename)
        {
            Project newproj = new Project();
            XDocument xdoc;
            XNamespace ns;

            newproj._path = filename;

            try
            {
                xdoc = XDocument.Load(newproj._path);
            }
            catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException || ex is ArgumentException || ex is System.Xml.XmlException)
            {
                ConsoleHelper.ColorWriteLine(ConsoleColor.Red, "Couldn't load project: '" + newproj._path + "': " + ex.Message);
                return null;
            }

            ns = xdoc.Root.Name.Namespace;

            newproj._proj_guids = xdoc
                .Elements(ns + "Project")
                .Elements(ns + "PropertyGroup")
                .Elements(ns + "ProjectGuid")
                .Select(g => g.Value)
                .ToList();

            newproj._ProjectTypeGuids = xdoc
                .Elements(ns + "Project")
                .Elements(ns + "PropertyGroup")
                .Elements(ns + "ProjectTypeGuids")
                .SelectMany(g => g.Value.Split(';'))
                .ToList();

            newproj._outputpaths = xdoc
                .Elements(ns + "Project")
                .Elements(ns + "PropertyGroup")
                .Elements(ns + "OutputPath")
                .Select(el => new OutputPath() { Condition = GetCondition(el), Path = el.Value })
                .ToList();

            newproj._outdirs = xdoc
                .Elements(ns + "Project")
                .Elements(ns + "PropertyGroup")
                .Elements(ns + "OutDir")
                .Select(el => new OutputPath() { Condition = GetCondition(el), Path = el.Value })
                .ToList();

            newproj._projectReferences = xdoc
                .Elements(ns + "Project")
                .Elements(ns + "ItemGroup")
                .Elements(ns + "ProjectReference")
                .Where(el => el.Attribute("Include") != null)
                .OrderBy(el => Path.GetFileNameWithoutExtension(el.Attribute("Include").Value))
                .Select(el => new Reference
                {
                    include = el.Attribute("Include").Value,
                    shortinclude = Path.GetFileNameWithoutExtension(el.Attribute("Include").Value),
                    names = el
                        .Elements(ns + "Name")
                        .OrderBy(elName => elName.Value)
                        .Select(elName => elName.Value)
                        .ToList(),
                    name = null
                })
                .ToList();

            newproj.Compact();

            return newproj;
        }