Exemple #1
0
        public void AddProjectReference(CsProj referencedProject)
        {
            if (this == referencedProject)
            {
                return;
            }

            if (ContainsProjectReference(referencedProject))
            {
                return;
            }

            Cauldron.Add($"Adding {referencedProject.Filepath} project reference to {Filepath}");
            Uri mercurySourcePath     = new Uri(Filepath);
            Uri referencedProjectPath = new Uri(referencedProject.Filepath);
            Uri relPath        = mercurySourcePath.MakeRelativeUri(referencedProjectPath);
            var projectRefPath = relPath.ToString().Replace("/", "\\");

            var regex = new Regex(_itemGroupProjectReferencePattern);

            Text = regex.Replace(Text, _itemGroupProjectReference +
                                 "Include=\"" + projectRefPath + "\">" + Environment.NewLine +
                                 "<Project>{" + referencedProject.Guid + "}</Project>" + Environment.NewLine +
                                 "<Name>" + referencedProject.Name + "</Name>" + Environment.NewLine +
                                 "</ProjectReference>" + Environment.NewLine +
                                 "<ProjectReference ", 1);
            WriteFile();
            ReformatXml(Filepath);
            _csProjCache = null;
        }
Exemple #2
0
 public static IEnumerable <NugetPackageReference> GetNugetReferences(CsProj csproj)
 {
     return(csproj.NugetReferences.Concat(
                csproj.References.SelectMany(GetNugetReferences)
                )
            .Distinct());
 }
Exemple #3
0
 private void AddDebugAndReleaseInformation(CsProj projectToAdd)
 {
     Text = Text.ReplaceLastOccurrence(_releaseAnyCpu,
                                       _releaseAnyCpu +
                                       Environment.NewLine + $"\t\t{{{projectToAdd.Guid.ToUpper()}}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU" +
                                       Environment.NewLine + $"\t\t{{{projectToAdd.Guid.ToUpper()}}}.Debug|Any CPU.Build.0 = Debug|Any CPU" +
                                       Environment.NewLine + $"\t\t{{{projectToAdd.Guid.ToUpper()}}}.Release|Any CPU.ActiveCfg = Release|Any CPU" +
                                       Environment.NewLine + $"\t\t{{{projectToAdd.Guid.ToUpper()}}}.Release|Any CPU.Build.0 = Release|Any CPU");
 }
Exemple #4
0
        public static CsProj Get(string path)
        {
            CsProj result;

            if (!CsProjPool.TryGetValue(path, out result))
            {
                result = new CsProj(path);
                CsProjPool.Add(path, result);
            }
            return(result);
        }
Exemple #5
0
        public static IEnumerable <SlnFile> SolutionsThatReference(CsProj csProj)
        {
            var slns = Wand.GetSolutionFiles(Wand.MercurySourceDir);

            foreach (var slnFile in slns)
            {
                if (slnFile.ContainsProjectReference(csProj))
                {
                    yield return(slnFile);
                }
            }
        }
Exemple #6
0
        public void AddProjectReference(CsProj projectToAdd, string solutionFolder = null)
        {
            AddProjectText(projectToAdd);
            AddDebugAndReleaseInformation(projectToAdd);
            if (solutionFolder != null)
            {
                AddToFolder(projectToAdd, solutionFolder);
            }

            WriteFile();
            _csProjsCache = null;
        }
Exemple #7
0
        private void AddProjectText(CsProj projectToAdd)
        {
            Uri mercurySourcePath     = new Uri(Wand.MercurySourceDir);
            Uri referencedProjectPath = new Uri(projectToAdd.Filepath);
            Uri relPath = mercurySourcePath.MakeRelativeUri(referencedProjectPath);

            Text = Text.ReplaceLastOccurrence(_endProject,
                                              _endProject + "\n" + "Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = " +
                                              $"\"{projectToAdd.Name}\"," +
                                              $" \"{relPath.ToString().Replace("src", "").Replace("/", "\\").TrimStart('\\')}\", " +
                                              $"\"{{{projectToAdd.Guid.ToUpper()}}}\"\r\n" +
                                              "EndProject");
        }
Exemple #8
0
        public bool ContainsProjectReference(CsProj project)
        {
            var guid           = project.Guid;
            var upperGuidRegex = guid.ToUpper().Replace("-", "\\-");
            var lowerGuidRegex = guid.ToLower().Replace("-", "\\-");

            if (new Librarian("<Project>{" + upperGuidRegex + "}<\\/Project>", Text).HasMatch() ||
                new Librarian("<Project>{" + lowerGuidRegex + "}<\\/Project>", Text).HasMatch())
            {
                return(true);
            }
            return(false);
        }
Exemple #9
0
 private CsProj[] GetCsProjs()
 {
     if (_csProjsCache == null)
     {
         var dir = Path.GetDirectoryName(Filepath);
         _csProjsCache = new Librarian(_csProjPattern, Text)
                         .Get("capturegroup")
                         .Select(csProjRelPath => Path.Combine(dir, csProjRelPath))
                         .Where(File.Exists)
                         .Select(file => CsProj.Get(file))
                         .ToArray();
     }
     return(_csProjsCache);
 }
Exemple #10
0
        public static HashSet <CsProj> GetAllProjectReferences(CsProj csProj)
        {
            if (csProj.References.Length == 0)
            {
                return(new HashSet <CsProj>());
            }

            HashSet <CsProj> references = new HashSet <CsProj>();

            references.AddRange(csProj.References);

            foreach (var csProjToTraverse in csProj.References)
            {
                references.AddRange(GetAllProjectReferences(csProjToTraverse));
            }
            return(references);
        }
Exemple #11
0
        private void AddToFolder(CsProj projectToAdd, string solutionFolder)
        {
            if (!SolutionFolderExists(solutionFolder))
            {
                CreateSolutionFolder(solutionFolder);
            }

            var solutionFolderGuid =
                new Librarian($"Project.* = \\\"{solutionFolder}\\\", \\\"{solutionFolder}\\\", \\\"" +
                              "\\{(?<capturegroup>(.*))\\}\\\"", Text)
                .Get("capturegroup")
                .ToArray();

            string projectToAddEqualsFolderToAdd = $"{{{projectToAdd.Guid.ToUpper()}}} = {{{solutionFolderGuid.Single()}}}";

            var reg = new Regex(_endGlobalSection);

            Text = reg.Replace(Text,
                               "}" + Environment.NewLine + "\t\t" + projectToAddEqualsFolderToAdd + Environment.NewLine + "\tEndGlobalSection", 1);
        }
Exemple #12
0
        public bool HasEvidenceOf(CsProj csProj)
        {
            throw new NotImplementedException(); //https://github.com/Jordan466/ItsMagic/issues/21

            foreach (var @class in csProj.Classes())
            {
                if (new Librarian("[\\s:]" + @class + "[\\s\\.(]", Text).HasMatch())
                {
                    Cauldron.Add($"Found Evidence of {csProj.Name}.{@class} in {Name}.cs");
                    return(true);
                }
            }
            //foreach(var extensionMethod in csProj.ExtensionMethods)
            //{
            //    if (RegexStore.Contains("\\." + extensionMethod + "\\(", Text()))
            //    {
            //        return true;
            //    }
            //}
            return(false);
        }
Exemple #13
0
        public static void RepairProjectReferences(CsProj csProj)
        {
            if (RepairedProjects.Contains(csProj.Filepath))
            {
                return;
            }

            foreach (var csProjReference in csProj.References)
            {
                RepairProjectReferences(csProjReference);
            }

            foreach (var csProjDependency in CsProj.GetAllProjectReferences(csProj))
            {
                csProj.AddProjectReference(csProjDependency);
            }

            foreach (var nugetDependency in CsProj.GetNugetReferences(csProj))
            {
                csProj.AddNugetReference(nugetDependency);
            }

            RepairedProjects.Add(csProj.Filepath);
        }
Exemple #14
0
 public bool ContainsProjectReference(CsProj referencedProject)
 {
     return(Text.Contains(referencedProject.Guid.ToUpper()));
 }
Exemple #15
0
 public static SlnFile[] GetSolutionsReferencing(CsProj csProj)
 {
     return(GetSolutionFiles(MercurySourceDir).Where(sln => sln.ContainsProjectReference(csProj.Guid)).ToArray());
 }
Exemple #16
0
 public static IEnumerable <CsProj> GetCsProjFiles(string dir)
 {
     return(Directory.EnumerateFiles(dir, "*.csproj", SearchOption.AllDirectories)
            .Select(file => CsProj.Get(file)));
 }