private void IncludeEfferentProjectReferences(CsProj project) { foreach (string projectGuid in project.ReferencedProjectGuids) { AddProjectSubtree(projectGuid); } }
private void IncludeEfferentAssemblyReferences(CsProj project) { foreach (string assemblyName in project.ReferencedAssemblyNames) { AddAssemblySubtree(assemblyName, project.TargetFrameworkVersion); } }
private void IncludeEfferentAssemblyReferences(CsProj project) { foreach (string assemblyName in project.ReferencedAssemblyNames) { AddAssemblySubtree(assemblyName); } }
private void ConvertToProjectReference(CsProj project, IEnumerable<CsProj> references) { var doc = LoadProject(project); var nav = doc.CreateNavigator(); foreach (var reference in references) { log.InfoFormat("Converting project {0} assembly reference {1} to project reference {2}.", project.AssemblyName, reference.AssemblyName, reference.Path); var xpath = string.Format("//msb:ItemGroup/msb:Reference[substring-before(concat(@Include, ','), ',') = '{0}']", reference.AssemblyName); var element = nav.SelectSingleNode(xpath, nsMgr); if (element == null) { log.ErrorFormat("Failed to locate Reference element in {0} for assembly {1}.", project.Path, reference.AssemblyName); continue; } var projectReference = doc.CreateElement("ProjectReference", MSBuildXmlNamespace); projectReference.SetAttribute("Include", reference.Path); projectReference.AppendChild(CreateElementWithInnerText(doc, "Project", reference.Guid)); projectReference.AppendChild(CreateElementWithInnerText(doc, "Name", reference.ProjectName)); var wrapper = doc.CreateElement("SlimJimReplacedReference", MSBuildXmlNamespace); wrapper.AppendChild(((XmlNode) element.UnderlyingObject).Clone()); projectReference.AppendChild(wrapper); element.ReplaceSelf(new XmlNodeReader(projectReference)); } doc.Save(project.Path); }
private void IncludeEfferentProjectReferences(CsProj project) { foreach (var referencedProj in project.ReferencedProjects) { AddProjectSubtree(referencedProj.Value); } }
protected XmlDocument LoadProject(CsProj project) { var doc = new XmlDocument(); doc.Load(project.Path); nsMgr = new XmlNamespaceManager(doc.NameTable); nsMgr.AddNamespace("msb", MSBuildXmlNamespace); return doc; }
private CsProj AddAssemblySubtree(string assemblyName, string targetFrameworkVersion = "") { CsProj project = FindProjectByAssemblyName(assemblyName, targetFrameworkVersion); AddProjectAndReferences(project); return(project); }
public void HandlesTrailingSlashOnRootDirectory() { var sln = new Sln("sample") { ProjectsRootDirectory = "Fake/Example/" }; var proj = new CsProj { Path = "Fake/Example/ModuleA/ProjectA/ProjectA.csproj", Guid = Guid.NewGuid().ToString("B") }; sln.AddProjects(proj); Assert.That(sln.Folders.FirstOrDefault(f => f.FolderName == "ModuleA"), Is.Not.Null, "Folders"); }
private CsProj AddAssemblySubtree(string assemblyName) { CsProj project = FindProjectByAssemblyName(assemblyName); AddProjectAndReferences(project); return(project); }
public void CreatesNestedSolutionFolders() { var sln = new Sln("sample") { ProjectsRootDirectory = "Fake/Example" }; var proj = new CsProj { Path = "Fake/Example/Grouping1/ModuleA/ProjectA/ProjectA.csproj", Guid = Guid.NewGuid().ToString("B")}; sln.AddProjects(proj); var child = sln.Folders.First(f => f.FolderName == "ModuleA"); var parent = sln.Folders.First(f => f.FolderName == "Grouping1"); Assert.That(parent.ContentGuids, Is.EqualTo(new[] {child.Guid})); Assert.That(child.ContentGuids, Is.EqualTo(new[] { proj.Guid })); }
private void AddProjectAndReferences(CsProj project) { if (project != null) { AddProject(project); IncludeEfferentProjectReferences(project); if (options.IncludeEfferentAssemblyReferences) { IncludeEfferentAssemblyReferences(project); } } }
private void AddAfferentReferencesToProject(CsProj project) { if (project != null) { List <CsProj> afferentAssemblyReferences = projectsList.FindAll( csp => csp.ReferencedAssemblyNames.Contains(project.AssemblyName)); AddAfferentReferences(afferentAssemblyReferences); List <CsProj> afferentProjectReferences = projectsList.FindAll(csp => csp.ReferencedProjectGuids.Contains(project.Guid)); AddAfferentReferences(afferentProjectReferences); } }
private void AddAfferentReferencesToProject(CsProj project) { if (project != null) { List<CsProj> afferentAssemblyReferences = projectsList.FindAll( csp => csp.ReferencedAssemblyNames.Contains(project.AssemblyName)); AddAfferentReferences(afferentAssemblyReferences); List<CsProj> afferentProjectReferences = projectsList.FindAll(csp => csp.ReferencedProjectGuids.Contains(project.Guid)); AddAfferentReferences(afferentProjectReferences); } }
private void AddAfferentReferencesToProject(CsProj project) { if (project != null) { var afferentAssemblyReferences = _projectsList.FindAll( csp => csp.ReferencedAssemblyNames.Contains(project.AssemblyName)); AddAfferentReferences(afferentAssemblyReferences); var afferentProjectReferences = _projectsList.FindAll(csp => csp.ReferencedProjects.Select(tuple => tuple.Value).Contains(project.Guid)); AddAfferentReferences(afferentProjectReferences); } }
private void RestoreAssemblyReferencesInProject(CsProj project) { var doc = LoadProject(project); var nav = doc.CreateNavigator(); XPathNavigator projectReference; while ((projectReference = nav.SelectSingleNode("//msb:ProjectReference[msb:SlimJimReplacedReference and 1]", nsMgr)) != null) { var original = projectReference.SelectSingleNode("./msb:SlimJimReplacedReference/msb:Reference", nsMgr); log.InfoFormat("Restoring project {0} assembly reference to {1}", project.ProjectName, projectReference.GetAttribute("Include", "")); projectReference.ReplaceSelf(original); } doc.Save(project.Path); }
private void AddPartialProjectGraphToSln(SlnGenerationOptions options) { Log.Info("Building partial graph solution for target projects: " + string.Join(", ", options.TargetProjectNames)); foreach (string targetProjectName in options.TargetProjectNames) { CsProj rootProject = AddAssemblySubtree(targetProjectName); if (rootProject == null) { Log.WarnFormat("Project {0} not found.", targetProjectName); } AddAfferentReferencesToProject(rootProject); } }
private void AddProjectToFolder(CsProj proj) { if (string.IsNullOrEmpty(ProjectsRootDirectory) || !proj.Path.StartsWith(ProjectsRootDirectory, StringComparison.InvariantCultureIgnoreCase)) { return; } var relativeFolderPath = GetSolutionFolderPath(proj); if (string.IsNullOrEmpty(relativeFolderPath)) { return; } var folder = GetOrCreateSolutionFolder(relativeFolderPath); folder.AddContent(proj.Guid); }
private void AddProject(CsProj project) { builtSln.AddProjects(project); }
private void AddProjectSubtree(string projectGuid) { CsProj referencedProject = FindProjectByProjectGuid(projectGuid); AddProjectAndReferences(referencedProject); }
private string GetSolutionFolderPath(CsProj proj) { var relativeProjectPath = proj.Path.Substring(ProjectsRootDirectory.Length + 1); return(Path.GetDirectoryName(Path.GetDirectoryName(relativeProjectPath))); }
private void ConvertProjectHintPaths(CsProj project, string packagesDir, Mode mode = Mode.Convert) { var doc = LoadProject(project); var nav = doc.CreateNavigator(); var nugetHintPaths = nav.Select("//msb:ItemGroup/msb:Reference/msb:HintPath", nsMgr) .Cast<XPathNavigator>() .Where(e => e.Value.Contains(NuGetPackagesDirectoryName)) .ToList(); if (!nugetHintPaths.Any()) return; var firstIndex = nugetHintPaths.First().Value.IndexOf(NuGetPackagesDirectoryName, StringComparison.InvariantCultureIgnoreCase); if (nugetHintPaths.Any(e => e.Value.IndexOf(NuGetPackagesDirectoryName, StringComparison.InvariantCultureIgnoreCase) != firstIndex)) { log.WarnFormat("Project {0} does not have consistent HintPath values for nuget packages. Skipping.", project.Path); return; } log.InfoFormat("Converting nuget hint paths in project {0}.", project.Path); var originalPackageDir = nugetHintPaths.First().Value.Substring(0, firstIndex + NuGetPackagesDirectoryName.Length); string relativePackagesDir; if (mode == Mode.Convert) { relativePackagesDir = CalculateRelativePathToSlimjimPackages(packagesDir, project.Path); } else { var e = doc.SelectSingleNode("//msb:PropertyGroup/msb:SlimJimOriginalPackageDir", nsMgr); if (e == null) { log.WarnFormat("Not restoring hint paths to project {0} because it does not have property SlimJimOriginalPackageDir defined.", project.Path); return; } relativePackagesDir = e.InnerText; e.ParentNode.RemoveChild(e); } foreach (var hintPath in nugetHintPaths) { var modifiedHintPath = Path.Combine(relativePackagesDir, hintPath.Value.Substring(firstIndex + NuGetPackagesDirectoryName.Length)); log.DebugFormat("Change hint path from {0} to {1}", hintPath.Value, modifiedHintPath); var element = CreateElementWithInnerText(doc, "HintPath", modifiedHintPath); hintPath.ReplaceSelf(element.CreateNavigator()); } if (mode == Mode.Convert) { var firstPropertyGroup = doc.SelectSingleNode("//msb:PropertyGroup[1]", nsMgr); if (firstPropertyGroup.SelectSingleNode("msb:SlimJimOriginalPackageDir", nsMgr) == null) { firstPropertyGroup.AppendChild(CreateElementWithInnerText(doc, "SlimJimOriginalPackageDir", originalPackageDir)); } } doc.Save(project.Path); }
private void RestoreAssemblyReferencesInProject(CsProj project) { var doc = new XmlDocument(); doc.Load(project.Path); var nav = doc.CreateNavigator(); var nsMgr = new XmlNamespaceManager(doc.NameTable); nsMgr.AddNamespace("msb", MSBuildXmlNamespace); XPathNavigator projectReference; while ((projectReference = nav.SelectSingleNode("//msb:ProjectReference[msb:SlimJimReplacedReference and 1]", nsMgr)) != null) { var original = projectReference.SelectSingleNode("./msb:SlimJimReplacedReference/msb:Reference", nsMgr); Log.InfoFormat("Restoring project {0} assembly reference to {1}", project.ProjectName, projectReference.GetAttribute("Include", "")); projectReference.ReplaceSelf(original); } doc.Save(project.Path); }
private void AddProjectToFolder(CsProj proj) { if (string.IsNullOrEmpty(ProjectsRootDirectory) || !proj.Path.StartsWith(ProjectsRootDirectory, StringComparison.InvariantCultureIgnoreCase)) { return; } var relativeFolderPath = GetSolutionFolderPath(proj); if (string.IsNullOrEmpty(relativeFolderPath)) return; var folder = GetOrCreateSolutionFolder(relativeFolderPath); folder.AddContent(proj.Guid); }
private string GetSolutionFolderPath(CsProj proj) { var relativeProjectPath = proj.Path.Substring(ProjectsRootDirectory.Length + 1); return Path.GetDirectoryName(Path.GetDirectoryName(relativeProjectPath)); }