public override void ProjectFinishedGenerating(Project project) { try { if(this.WizardRunKind != WizardRunKind.AsMultiProject) return; if(project == null) project = this.GetProject(this.ProjectName); // We need to move the test-projects before the project itself, to get rid of directories. var testProjects = this.GetTestProjects().Select(this.MoveProjectOneDirectoryUp).ToArray(); project = this.MoveProjectOneDirectoryUp(project); foreach(var testProject in testProjects) { var testProjectFilePath = testProject.FullName; var projectContainer = project.Parent(); // We remove them and add them again to get them added after the main-project, see variable "project" above. this.Solution.Remove(testProject); var refreshedTestProject = projectContainer.AddFromFile(testProjectFilePath); ((VSProject) refreshedTestProject.Object).References.AddProject(project); } } catch(Exception exception) { this.HandleException(exception); } }
protected internal virtual Project MoveProject(Project project, string destinationDirectory) { if(project == null) throw new ArgumentNullException("project"); var projectFile = this.FileSystem.FileInfo.FromFileName(project.FullName); var sourceDirectory = projectFile.DirectoryName; var projectContainer = project.Parent(); this.Solution.Remove(project); if(this.FileSystem.Directory.Exists(destinationDirectory)) { var destinationDirectoryParent = this.FileSystem.DirectoryInfo.FromDirectoryName(destinationDirectory).Parent.FullName; var temporaryDestinationDirectory = this.FileSystem.Path.Combine(destinationDirectoryParent, Guid.NewGuid().ToString()); this.FileSystem.Directory.Move(sourceDirectory, temporaryDestinationDirectory); sourceDirectory = temporaryDestinationDirectory; this.FileSystem.Directory.Delete(destinationDirectory); } this.FileSystem.Directory.Move(sourceDirectory, destinationDirectory); var projectFileDestinationPath = this.FileSystem.Path.Combine(destinationDirectory, projectFile.Name); return projectContainer.AddFromFile(projectFileDestinationPath); }