/// <summary> /// Ensure the Directory Structure is correct. Projects are in proper place. /// </summary> /// <param name="solutionFile"></param> /// <returns></returns> private bool ProperDirectoryStructure(string solutionFile) { // Create src folder if it does not exist. if (!DirectoryExists(SourceDirectory)) { Directory.CreateDirectory(SourceDirectory.ToString()); } // Create Tests folder if it does not exist. if (!DirectoryExists(TestsDirectory)) { Directory.CreateDirectory(TestsDirectory.ToString()); } // Create Artifacts / Output folder if it does not exist. if (!DirectoryExists(OutputDirectory)) { Directory.CreateDirectory(OutputDirectory.ToString()); } // Query the solution for the projects that are in it. // We allow all tests to run, instead of failing at first failure. CurrentSolutionPath = (AbsolutePath)Path.GetDirectoryName(solutionFile); DotNetPath = ToolPathResolver.GetPathExecutable("dotnet"); IProcess slnfind = ProcessTasks.StartProcess(DotNetPath, "sln " + CurrentSolutionPath + " list", logOutput: true); slnfind.AssertWaitForExit(); IReadOnlyCollection <Output> output = slnfind.Output; // There are 2 things we need to check. // 1. Is solution in right folder? // 2. Are projects in right folder. // The Move process has to do the following: // 1. Move the project folder to proper place // 2. Remove the project from the solution // 3. Do steps 1, 2 for every project // 4. Move solution file to proper location // 5. Re-add all projects to solution bool solutionNeedsToMove = false; if (CurrentSolutionPath.ToString() != ExpectedSolutionPath.ToString()) { solutionNeedsToMove = true; } List <VisualStudioProject> movedProjects = new List <VisualStudioProject>(); // Step 3 foreach (Output outputRec in output) { if (outputRec.Text.EndsWith(".csproj")) { VisualStudioProject project = GetInitProject(outputRec.Text); Projects.Add(project); // Do we need to move the project? if ((project.OriginalPath.ToString() != project.NewPath.ToString()) || solutionNeedsToMove) { movedProjects.Add(project); MoveProjectStepA(project); } } } // Step 4: Is Solution in proper directory. If not move it. if (solutionNeedsToMove) { string slnFileCurrent = CurrentSolutionPath / Path.GetFileName(solutionFile); string slnFileFuture = ExpectedSolutionPath / Path.GetFileName(solutionFile); File.Move(slnFileCurrent, slnFileFuture); } // Step 5. Read project to solution if (movedProjects.Count > 0) { foreach (VisualStudioProject project in movedProjects) { MoveProjectStepB(project); } } return(true); }
/// <summary> /// Ensure the Directory Structure is correct. Projects are in proper place. /// </summary> /// <param name="solutionFile"></param> /// <returns></returns> private bool SlugCI_NewSetup_EnsureProperDirectoryStructure(string solutionFile) { bool solutionNeedsToMove = false; CurrentSolutionPath = CISession.Solution.Directory; if (CurrentSolutionPath.ToString() != ExpectedSolutionPath.ToString()) { solutionNeedsToMove = true; } // Query the solution for the projects that are in it. // We allow all tests to run, instead of failing at first failure. // There are 2 things we need to check. // 1. Is solution in right folder? // 2. Are projects in right folder. // The Move process has to do the following: // 1. Move the project folder to proper place // 2. Remove the project from the solution // 3. Do steps 1, 2 for every project // 4. Move solution file to proper location // 5. Re-add all projects to solution try { List <VisualStudioProject> movedProjects = new List <VisualStudioProject>(); foreach (VisualStudioProject vsProject in Projects) { if (vsProject.OriginalPath.ToString() != vsProject.NewPath.ToString() || solutionNeedsToMove) { movedProjects.Add(vsProject); MoveProjectStepA(vsProject); } } // Step 4: Is Solution in proper directory. If not move it. if (solutionNeedsToMove) { string slnFileCurrent = CurrentSolutionPath / Path.GetFileName(solutionFile); string slnFileFuture = ExpectedSolutionPath / Path.GetFileName(solutionFile); File.Move(slnFileCurrent, slnFileFuture); SolutionWasMoved = true; } // Step 5. Read project to solution if (movedProjects.Count > 0) { foreach (VisualStudioProject project in movedProjects) { MoveProjectStepB(project); } } } catch (Exception e) { AOT_Error("An error occured during the project migration to SlugCI format. Because of where this error occurred the project may be in an unusable state at this time."); AOT_Error("You can either revert all the changes in git, delete the entire project from this machine, re-clone it and start again, or attempt to fix it."); throw; } return(true); }