Esempio n. 1
0
 private void IncludeEfferentProjectReferences(CsProj project)
 {
     foreach (string projectGuid in project.ReferencedProjectGuids)
     {
         AddProjectSubtree(projectGuid);
     }
 }
Esempio n. 2
0
 private void IncludeEfferentAssemblyReferences(CsProj project)
 {
     foreach (string assemblyName in project.ReferencedAssemblyNames)
     {
         AddAssemblySubtree(assemblyName, project.TargetFrameworkVersion);
     }
 }
Esempio n. 3
0
 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);
        }
Esempio n. 5
0
 private void IncludeEfferentProjectReferences(CsProj project)
 {
     foreach (var referencedProj in project.ReferencedProjects)
     {
         AddProjectSubtree(referencedProj.Value);
     }
 }
Esempio n. 6
0
		protected XmlDocument LoadProject(CsProj project)
		{
			var doc = new XmlDocument();
			doc.Load(project.Path);
			nsMgr = new XmlNamespaceManager(doc.NameTable);
			nsMgr.AddNamespace("msb", MSBuildXmlNamespace);
			return doc;
		}
Esempio n. 7
0
        private CsProj AddAssemblySubtree(string assemblyName, string targetFrameworkVersion = "")
        {
            CsProj project = FindProjectByAssemblyName(assemblyName, targetFrameworkVersion);

            AddProjectAndReferences(project);

            return(project);
        }
Esempio n. 8
0
        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");
        }
Esempio n. 9
0
        private CsProj AddAssemblySubtree(string assemblyName)
        {
            CsProj project = FindProjectByAssemblyName(assemblyName);

            AddProjectAndReferences(project);

            return(project);
        }
Esempio n. 10
0
        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 }));
        }
Esempio n. 11
0
        private void AddProjectAndReferences(CsProj project)
        {
            if (project != null)
            {
                AddProject(project);

                IncludeEfferentProjectReferences(project);

                if (options.IncludeEfferentAssemblyReferences)
                {
                    IncludeEfferentAssemblyReferences(project);
                }
            }
        }
Esempio n. 12
0
        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);
            }
        }
Esempio n. 13
0
        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);
            }
        }
Esempio n. 14
0
        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);
            }
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        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);
            }
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
 private void AddProject(CsProj project)
 {
     builtSln.AddProjects(project);
 }
Esempio n. 19
0
        private void AddProjectSubtree(string projectGuid)
        {
            CsProj referencedProject = FindProjectByProjectGuid(projectGuid);

            AddProjectAndReferences(referencedProject);
        }
Esempio n. 20
0
        private string GetSolutionFolderPath(CsProj proj)
        {
            var relativeProjectPath = proj.Path.Substring(ProjectsRootDirectory.Length + 1);

            return(Path.GetDirectoryName(Path.GetDirectoryName(relativeProjectPath)));
        }
Esempio n. 21
0
        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);
        }
Esempio n. 22
0
        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);
        }
Esempio n. 23
0
        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);
        }
Esempio n. 24
0
        private void AddProjectAndReferences(CsProj project)
        {
            if (project != null)
            {
                AddProject(project);

                IncludeEfferentProjectReferences(project);

                if (options.IncludeEfferentAssemblyReferences)
                {
                    IncludeEfferentAssemblyReferences(project);
                }
            }
        }
Esempio n. 25
0
 private void IncludeEfferentAssemblyReferences(CsProj project)
 {
     foreach (string assemblyName in project.ReferencedAssemblyNames)
     {
         AddAssemblySubtree(assemblyName);
     }
 }
Esempio n. 26
0
 private void AddProject(CsProj project)
 {
     builtSln.AddProjects(project);
 }
Esempio n. 27
0
 private void IncludeEfferentProjectReferences(CsProj project)
 {
     foreach (string projectGuid in project.ReferencedProjectGuids)
     {
         AddProjectSubtree(projectGuid);
     }
 }
Esempio n. 28
0
        private string GetSolutionFolderPath(CsProj proj)
        {
            var relativeProjectPath = proj.Path.Substring(ProjectsRootDirectory.Length + 1);

            return Path.GetDirectoryName(Path.GetDirectoryName(relativeProjectPath));
        }
Esempio n. 29
0
 private void IncludeEfferentAssemblyReferences(CsProj project)
 {
     foreach (string assemblyName in project.ReferencedAssemblyNames)
     {
         AddAssemblySubtree(assemblyName, project.TargetFrameworkVersion);
     }
 }