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; }
public static IEnumerable <NugetPackageReference> GetNugetReferences(CsProj csproj) { return(csproj.NugetReferences.Concat( csproj.References.SelectMany(GetNugetReferences) ) .Distinct()); }
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"); }
public static CsProj Get(string path) { CsProj result; if (!CsProjPool.TryGetValue(path, out result)) { result = new CsProj(path); CsProjPool.Add(path, result); } return(result); }
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); } } }
public void AddProjectReference(CsProj projectToAdd, string solutionFolder = null) { AddProjectText(projectToAdd); AddDebugAndReleaseInformation(projectToAdd); if (solutionFolder != null) { AddToFolder(projectToAdd, solutionFolder); } WriteFile(); _csProjsCache = null; }
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"); }
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); }
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); }
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); }
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); }
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); }
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); }
public bool ContainsProjectReference(CsProj referencedProject) { return(Text.Contains(referencedProject.Guid.ToUpper())); }
public static SlnFile[] GetSolutionsReferencing(CsProj csProj) { return(GetSolutionFiles(MercurySourceDir).Where(sln => sln.ContainsProjectReference(csProj.Guid)).ToArray()); }
public static IEnumerable <CsProj> GetCsProjFiles(string dir) { return(Directory.EnumerateFiles(dir, "*.csproj", SearchOption.AllDirectories) .Select(file => CsProj.Get(file))); }