code_junkie

Visual Studio Extensibility: Adding existing folders to a project

Nov 10th, 2011
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. ProjectItem folder =
  2. item.ProjectItem.Collection.AddFolder(newDirectoryName, string.Empty);
  3.  
  4. DirectoryInfo dirInfo = new DirectoryInfo(newDirectoryParent +
  5. newDirectoryName);
  6. if (dirInfo.Exists)
  7. {
  8. dirInfo.Delete(true);
  9. }
  10.  
  11. ProjectItem folder =
  12. item.ProjectItem.Collection.AddFolder(newDirectoryName, string.Empty);
  13.  
  14. DirectoryInfo dirInfo = new DirectoryInfo(newDirectoryParent + newDirectoryName);
  15.  
  16. if (dirInfo.Exists)
  17. {
  18. dirInfo.Delete(true);
  19. item.DTE.ExecuteCommand("View.Refresh", string.Empty);
  20. }
  21.  
  22. ProjectItem folder = item.ProjectItem.Collection.AddFolder(newDirectoryName, string.Empty);
  23.  
  24. ProjectItem pi = null;
  25. var dir = Path.Combine(
  26. project.Properties.Item("LocalPath").Value.ToString(), SubdirectoryName);
  27. if (Directory.Exists(dir))
  28. pi = target.ProjectItems.AddFromDirectory(dir);
  29. else
  30. pi = target.ProjectItems.AddFolder(dir);
  31.  
  32. <ItemGroup>
  33. <compile include="pathrootFolderToInclude***.cs" />
  34. </ItemGroup>
  35.  
  36. //Getting the current project
  37. private DTE2 _applicationObject;
  38. System.Array projs = (System.Array)_applicationObject.ActiveSolutionProjects;
  39. Project proy=(Project)projs.GetValue(0);
  40. //Getting the path
  41. string path=proy.FullName.Substring(0,proy.FullName.LastIndexOf('\'));
  42. //Valitating if the path exists
  43. bool existsDirectory= Directory.Exists(path + "\Directory");
  44. //Deleting and creating the Directory
  45. if (existeClasses)
  46. Directory.Delete(path + "\Directory", true);
  47. Directory.CreateDirectory(path + "\Directory");
  48. //Including in the project
  49. proy.ProjectItems.AddFromDirectory(path + "\Directory");
Add Comment
Please, Sign In to add comment