Exemple #1
0
        public void WriteProject(string solutionfile, bool simulate, bool nobackup)
        {
            XDocument xdoc;
            string    fullfilename = Path.Combine(Path.GetDirectoryName(solutionfile), _sln_path);

            try
            {
                xdoc = XDocument.Load(fullfilename);
            }
            catch (IOException ex)
            {
                Console.WriteLine($"Couldn't load project: '{fullfilename}': {ex.Message}");
                return;
            }
            catch (System.Xml.XmlException ex)
            {
                Console.WriteLine($"Couldn't load project: '{fullfilename}': {ex.Message}");
                return;
            }


            ConsoleHelper.WriteLineDeferred($"-=-=- Saving project: '{_sln_path}' -=-=-");

            UpdateReferences(xdoc);
            UpdateProjectReferences(xdoc, solutionfile);

            /*if (_outputpath != null)
             * {
             *  UpdateOutputPath(xdoc, solutionfile, outputpath);
             * }*/


            string bakfile = $"{fullfilename}.bak.xml";

            ConsoleHelper.WriteLine($"  Writing file: '{fullfilename}'.", true);
            if (!simulate)
            {
                if (!nobackup)
                {
                    if (File.Exists(bakfile))
                    {
                        FileHelper.RemoveRO(bakfile);
                        File.Delete(bakfile);
                    }

                    File.Move(fullfilename, bakfile);
                }

                xdoc.Save(fullfilename);
            }

            ConsoleHelper.WriteLineDeferred(null);

            return;
        }
Exemple #2
0
        public bool FixProjects(List <Project> projects, List <string> hintpaths, string outputpath, bool copylocal, bool removeversion)
        {
            bool valid = true;

            foreach (Project p in projects.OrderBy(p => p._sln_path))
            {
                p.Compact();
            }

            foreach (Project p in projects.OrderBy(p => p._sln_path))
            {
                p.CompactRefs();
            }

            ConsoleHelper.WriteLineDeferred("-=-=- Validating -=-=-");
            foreach (Project p in projects.OrderBy(p => p._sln_path))
            {
                if (!p.Validate(_solutionfile, projects))
                {
                    valid = false;
                }
            }
            ConsoleHelper.WriteLineDeferred(null);

            if (!valid)
            {
                ConsoleHelper.ColorWrite(ConsoleColor.Red, "Fix errors before continuing!");
                return(false);
            }

            foreach (Project p in projects.OrderBy(p => p._sln_path))
            {
                p.Fix(_solutionfile, projects, hintpaths, outputpath, copylocal, removeversion);
            }

            return(true);  // Success
        }
Exemple #3
0
        public bool Fix(string solutionfile, List <Project> projects, List <string> hintpaths, string outputpath, bool copylocal, bool removeversion)
        {
            ConsoleHelper.WriteLineDeferred($"-=-=- Fixing project: '{_sln_path}' -=-=-");

            // ass -> proj
            foreach (AssemblyRef assref in _references.OrderBy(r => r.Shortinclude))
            {
                bool exists = projects.Any(p => p._proj_assemblyname == assref.Shortinclude);
                if (exists)
                {
                    ProjectRef projref = CreateProjectReferenceFromReference(solutionfile, projects, assref);
                    if (assref.Shortinclude == projref.Shortinclude)
                    {
                        ConsoleHelper.WriteLine($"  ref -> projref: '{assref.Shortinclude}'.", true);
                    }
                    else
                    {
                        ConsoleHelper.WriteLine($"  ref -> projref: '{assref.Shortinclude}' -> '{projref.Shortinclude}'.", true);
                    }

                    _projectReferences.Add(projref);
                    _references.Remove(assref);
                    _modified = true;
                }
            }


            // proj -> ass
            foreach (ProjectRef projref in _projectReferences.OrderBy(r => r.Shortinclude))
            {
                bool exists = projects.Any(p => p._sln_shortfilename == projref.Shortinclude);
                if (!exists)
                {
                    AssemblyRef assref = CreateReferenceFromProjectReference(solutionfile, projects, hintpaths, projref);
                    if (projref.Shortinclude == assref.Shortinclude)
                    {
                        ConsoleHelper.WriteLine($"  projref -> ref: '{projref.Shortinclude}'.", true);
                    }
                    else
                    {
                        ConsoleHelper.WriteLine($"  projref -> ref: '{projref.Shortinclude}' -> '{assref.Shortinclude}'.", true);
                    }

                    _references.Add(assref);
                    _projectReferences.Remove(projref);
                    _modified = true;
                }
            }


            // Fix hint paths
            foreach (AssemblyRef assref in _references.OrderBy(r => r.Shortinclude))
            {
                FixHintPath(solutionfile, hintpaths, assref);
            }


            if (outputpath != null)
            {
                /*// todo: Abs -> Rel?
                 * bool diff = _outputpaths.Any(o => o != outputpath);
                 * if (diff)
                 * {
                 *  _outputpaths = new List<string>();
                 *  _outputpaths.Add(outputpath);
                 *  _modified = true;
                 * }*/
            }

            if (removeversion)
            {
                foreach (AssemblyRef assref in _references.OrderBy(r => r.Shortinclude))
                {
                    string shortref = GetShortRef(assref.Include);
                    if (shortref != assref.Include)
                    {
                        ConsoleHelper.WriteLine($"  ref: removing version: '{assref.Include}' -> '{shortref}'.", true);
                        assref.Include      = shortref;
                        assref.Shortinclude = shortref;

                        _modified = true;
                    }
                }
            }

            ConsoleHelper.WriteLineDeferred(null);

            return(true);
        }