private void UpdateSolutionWithFolderTargets(SolutionTool solutionTool, FolderTool folderTool)
        {
            var matchingTargets = GetMatchingTargets(solutionTool, folderTool, _logger);

            var relativePath = folderTool.FolderPath.RemoveCommonPrefix(solutionTool.FolderPath, System.IO.Path.DirectorySeparatorChar, StringComparison.InvariantCultureIgnoreCase);

            var subFolders = relativePath.Split(new char[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);

            var addedProjects = new List <SolutionProjectItem>();
            SolutionProjectItem parentFolderProject = null;

            foreach (var subfolder in subFolders)
            {
                parentFolderProject = solutionTool.AddFolderProject(subfolder, parentFolderProject?.Id);
                addedProjects.Add(parentFolderProject);
                _logger.LogProgress();
            }

            solutionTool.AddProjects(matchingTargets, parentFolderProject?.Id);

            solutionTool.Save();
        }
        public void ReTransmogrifyProjectsToNugetPackages(SolutionTool solutionTool, FolderTool folderTool)
        {
            var projectsToRemove = folderTool.GetProjects();

            var solutionProjectItems     = solutionTool.GetProjectsWithParents().ToArray();
            var solutionProjectsToRemove = solutionProjectItems.Where(p => projectsToRemove.Any(p2 => p2.Name == p.Name)).ToArray();

            var possibleParentsToKill = new List <SolutionProjectItem>();

            foreach (var solutionProjectToRemove in solutionProjectsToRemove)
            {
                if (solutionProjectToRemove.ParentId != Guid.Empty)
                {
                    var parentProject = solutionProjectItems.Single(p => p.Id == solutionProjectToRemove.ParentId);
                    if (!possibleParentsToKill.Contains(parentProject))
                    {
                        possibleParentsToKill.Add(parentProject);
                    }
                }
                _logger.LogInformation($"Remove {solutionProjectToRemove.Name}");
                _logger.LogProgress();
            }

            var dependentProjects = solutionProjectItems.Where(p =>
                                                               solutionProjectsToRemove.All(p2 => p2.Name != p.Name) &&
                                                               (p.Type == SolutionTool.ProjectTypeIdClassLibrary || p.Type == SolutionTool.ProjectTypeIdWebProject));

            foreach (var dependentProject in dependentProjects)
            {
                var projectPath = System.IO.Path.Combine(solutionTool.FolderPath, dependentProject.Path);
                var projectTool = new ProjectTool(projectPath, _logger);

                var projectReferences = projectTool.GetProjectReferences().ToArray();
                var packageReferences = projectTool.GetPackageReferences().ToArray();

                _logger.LogInformation($"References in project {dependentProject.Name}");
                var dependencies = new List <NugetPackage>();

                var projectReferencesToRemove = projectReferences.Where(pr => solutionProjectsToRemove.Any(p => p.Name == pr.Name)).ToArray();
                foreach (var projectReference in projectReferencesToRemove)
                {
                    var projectReferencePath = PathExtensions.GetAbsolutePath(projectTool.FolderPath, projectReference.HintPath);
                    var projectReferenceTool = new ProjectTool(projectReferencePath, _logger);

                    var targetFramework  = projectReferenceTool.GetTargetFramework();
                    var nugetPackageTool = NugetPackageTool.GetNugetPackageTool(solutionTool.FolderPath, projectReference.Name, targetFramework);
                    if (nugetPackageTool != null)
                    {
                        var nuspec = nugetPackageTool.GetNuspec();

                        _logger.LogInformation($"\t{projectReference.Name} - {projectReference.HintPath} - {nuspec.Name} {nuspec.Version}");

                        foreach (var dependency in nuspec.Dependencies)
                        {
                            if (dependencies.All(a => a.Name != dependency.Name) &&
                                packageReferences.All(r => r.Name != dependency.Name) &&
                                solutionProjectsToRemove.All(p => p.Name != dependency.Name))
                            {
                                dependencies.Add(new NugetPackage {
                                    Name = dependency.Name, Version = dependency.Version, TargetFramework = targetFramework
                                });
                                _logger.LogInformation($"\t\tSub Nuget dependency {dependency.Name} {dependency.Version}");
                            }
                        }
                        _logger.LogProgress();

                        if (dependencies.All(a => a.Name != nuspec.Name) &&
                            packageReferences.All(r => r.Name != nuspec.Name))
                        {
                            dependencies.Add(new NugetPackage {
                                Name = nuspec.Name, Version = nuspec.Version.ToString(), TargetFramework = targetFramework
                            });
                        }

                        projectTool.RemoveProjectReference(projectReference);
                        projectTool.AddNugetReference(nuspec.Name, nuspec.Version.ToString(), nugetPackageTool.TargetFrameworkVersion);
                    }
                    else
                    {
                        _logger.LogInformation($"\t{projectReference.Name} - {projectReference.HintPath} - NO NUGET");
                    }
                    _logger.LogProgress();
                }

                foreach (var dependency in dependencies)
                {
                    var nugetPackageTool = new NugetPackageTool(solutionTool.FolderPath, dependency.Name, dependency.Version, dependency.TargetFramework);

                    var libReferences = nugetPackageTool.GetLibPaths();
                    foreach (var libReference in libReferences)
                    {
                        projectTool.AddReference(libReference);
                        _logger.LogProgress();
                    }
                    _logger.LogProgress();
                }

                projectTool.Save();
            }

            foreach (var solutionProjectToRemove in solutionProjectsToRemove)
            {
                solutionTool.RemoveProject(solutionProjectToRemove);
                _logger.LogProgress();
            }
            solutionTool.Save();
        }