public void AddProjectsUnderPathToSolution(Solution4 solution, string folderPath, string pattern = @"*.*proj") { string[] projFiles = Directory.GetFiles(folderPath, pattern, SearchOption.AllDirectories); bool hadErrors = false; StringBuilder errorsb = new StringBuilder(); var slnProjects = GetProjects(); List <string> slnProjectNames = new List <string>(); if (slnProjects != null) { slnProjectNames = (from p in slnProjects select p.Name.ToLowerInvariant()).ToList(); } foreach (string path in projFiles) { try { var pathInfo = new FileInfo(path); if (!slnProjectNames.Contains(pathInfo.Name.ToLowerInvariant())) { Project projectAdded = solution.AddFromFile(path, false); } } catch (Exception ex) { errorsb.AppendLine(ex.ToString()); } } if (hadErrors) { MessageBox.Show(errorsb.ToString()); } }
public void RunFinished() { if (_solution == null) { throw new Exception("No solution found."); } //Get all projects in solution var projects = GetProjects().Except(_existingProjects).ToList(); if (projects == null || !projects.Any()) { throw new Exception("No projects found."); } //Get the projects directory from first project. var projectsDir = Path.GetDirectoryName(Path.GetDirectoryName(projects.First().FullName)); if (projectsDir == null) { return; } //Change the projects location. var solutionStructure = projects.Select(AdjustProjectLocation).ToList(); //Remove the projects from the solution foreach (var project in projects) { _solution.Remove(project); } //Restructure solution foreach (var keyValuePair in solutionStructure.Where(keyValuePair => !string.IsNullOrWhiteSpace(keyValuePair.Value))) { if (keyValuePair.Key != null) { //If Key is not null, The project needs to be added to a SolutionFolder var slnDirectory = keyValuePair.Key.Object as SolutionFolder; if (slnDirectory != null) { slnDirectory.AddFromFile(keyValuePair.Value); } } else { //Key is null, add project to Solution root. _solution.AddFromFile(keyValuePair.Value); } } ThreadPool.QueueUserWorkItem(state => { //Wait for *.sln file and obsolete folder to be created. System.Threading.Thread.Sleep(4000); //Delete the old directory DeleteDirectory(projectsDir); }); }
public void AddProjectsUnderPathToSolution(Solution4 solution, string folderPath, string pattern = @"*.*proj") { string[] projFiles = Directory.GetFiles(folderPath, pattern, SearchOption.AllDirectories); bool hadErrors = false; StringBuilder errorsb = new StringBuilder(); foreach (string path in projFiles) { // TODO: Check to see if the project is already added to the solution try { Project projectAdded = solution.AddFromFile(path, false); // ProjectHelper.UpdatePackagesPathInProject(projectAdded,GetSolution()); } catch (Exception ex) { errorsb.AppendLine(ex.ToString()); } } if (hadErrors) { MessageBox.Show(errorsb.ToString()); } }
public void AddFromFile(string filePath) { Solution.AddFromFile(filePath); }
private static void ResolveProject(Solution4 solution, Projects projects, Project project) { var vsProject = project.Object as VSProject2; if (vsProject == null) return; // load ivymodules List<KeyValuePair<IvyModule, string>> ivyModules = GetIvyModules(project); References references = vsProject.References; foreach (Reference3 reference in references) { if (reference.Type == prjReferenceType.prjReferenceTypeAssembly && reference.SourceProject == null) { KeyValuePair<IvyModule, string> matching = ivyModules.SingleOrDefault(kvp => kvp.Key.Publications.ArtifactList.Count(artifact => artifact.Filename == Path.GetFileName(reference.Path)) > 0); if (matching.Key == null || matching.Value == null) { Output.Instance.WriteLine("Could not find a matching ivy module for reference '" + reference.Name + "'"); continue; } Output.Instance.WriteLine("Found matching ivy module for reference '" + reference.Name + "'"); // project base directory var projectDirectory = new DirectoryInfo(Path.GetDirectoryName(matching.Value)); Output.Instance.WriteLine("Ivy modules base directory is '" + projectDirectory.FullName + "'"); if (!projectDirectory.Exists) { Output.Instance.WriteLine("The directory does not seem to exist, will skip this reference!"); continue; } // find the project file which exists in the directory FileInfo[] projectFiles = projectDirectory.GetFiles("*.csproj", SearchOption.TopDirectoryOnly); if (projectFiles.Length == 0 || projectFiles.Length > 1) { Output.Instance.WriteLine("Could not find a project file in the directory '" + projectDirectory.FullName + "', will skip this reference"); continue; } // get the first project file, as a rule it should only exist one FileInfo projectFile = projectFiles.First(); Output.Instance.WriteLine("The selected project file for reference '" + reference.Name + "' is '" + projectFile.FullName + "'"); Project result = null; // parse thru all existing projects to see if it already has been added foreach (Project proj in projects) { if (proj.FullName == projectFile.FullName) result = proj; } // if the project wasn't added earlier add it, and resolve its references if (result == null) { result = solution.AddFromFile(projectFile.FullName, false); ResolveProject(solution, projects, result); } // remove the old binary reference reference.Remove(); vsProject.References.AddProject(result); } } }
public void AddProjectsUnderPathToSolution(Solution4 solution, string folderPath,string pattern=@"*.*proj") { string[] projFiles = Directory.GetFiles(folderPath, pattern, SearchOption.AllDirectories); bool hadErrors = false; StringBuilder errorsb = new StringBuilder(); foreach (string path in projFiles) { // TODO: Check to see if the project is already added to the solution try { Project projectAdded = solution.AddFromFile(path, false); // ProjectHelper.UpdatePackagesPathInProject(projectAdded,GetSolution()); } catch(Exception ex) { errorsb.AppendLine(ex.ToString()); } } if (hadErrors) { MessageBox.Show(errorsb.ToString()); } }
private static void ResolveProject(Solution4 solution, Projects projects, Project project) { var vsProject = project.Object as VSProject2; if (vsProject == null) { return; } // load ivymodules List <KeyValuePair <IvyModule, string> > ivyModules = GetIvyModules(project); References references = vsProject.References; foreach (Reference3 reference in references) { if (reference.Type == prjReferenceType.prjReferenceTypeAssembly && reference.SourceProject == null) { KeyValuePair <IvyModule, string> matching = ivyModules.SingleOrDefault(kvp => kvp.Key.Publications.ArtifactList.Count(artifact => artifact.Filename == Path.GetFileName(reference.Path)) > 0); if (matching.Key == null || matching.Value == null) { Output.Instance.WriteLine("Could not find a matching ivy module for reference '" + reference.Name + "'"); continue; } Output.Instance.WriteLine("Found matching ivy module for reference '" + reference.Name + "'"); // project base directory var projectDirectory = new DirectoryInfo(Path.GetDirectoryName(matching.Value)); Output.Instance.WriteLine("Ivy modules base directory is '" + projectDirectory.FullName + "'"); if (!projectDirectory.Exists) { Output.Instance.WriteLine("The directory does not seem to exist, will skip this reference!"); continue; } // find the project file which exists in the directory FileInfo[] projectFiles = projectDirectory.GetFiles("*.csproj", SearchOption.TopDirectoryOnly); if (projectFiles.Length == 0 || projectFiles.Length > 1) { Output.Instance.WriteLine("Could not find a project file in the directory '" + projectDirectory.FullName + "', will skip this reference"); continue; } // get the first project file, as a rule it should only exist one FileInfo projectFile = projectFiles.First(); Output.Instance.WriteLine("The selected project file for reference '" + reference.Name + "' is '" + projectFile.FullName + "'"); Project result = null; // parse thru all existing projects to see if it already has been added foreach (Project proj in projects) { if (proj.FullName == projectFile.FullName) { result = proj; } } // if the project wasn't added earlier add it, and resolve its references if (result == null) { result = solution.AddFromFile(projectFile.FullName, false); ResolveProject(solution, projects, result); } // remove the old binary reference reference.Remove(); vsProject.References.AddProject(result); } } }
public void AddProjectsUnderPathToSolution(Solution4 solution, string folderPath, string pattern = @"*.*proj") { string[] projFiles = Directory.GetFiles(folderPath, pattern, SearchOption.AllDirectories); bool hadErrors = false; StringBuilder errorsb = new StringBuilder(); var slnProjects = GetProjects(); List<string> slnProjectNames = new List<string>(); if(slnProjects != null) { slnProjectNames = (from p in slnProjects select p.Name.ToLowerInvariant()).ToList(); } foreach (string path in projFiles) { try { var pathInfo = new FileInfo(path); if (!slnProjectNames.Contains(pathInfo.Name.ToLowerInvariant())) { Project projectAdded = solution.AddFromFile(path, false); } } catch (Exception ex) { errorsb.AppendLine(ex.ToString()); } } if (hadErrors) { MessageBox.Show(errorsb.ToString()); } }