Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,32 +215,38 @@ private void RenameProject(Project project, DTE2 dte)
return ProjectFileService.RenameProjectFile(projectFilePath, newName);
}, out projectFilePath);

// Step 7: Rename parent directory if it matches the old project name
// Step 7: Rename sibling files (e.g., .csproj.user, .vcxproj.filters)
ExecuteStep(progressDialog, stepIndex++, () =>
{
ProjectFileService.RenameSiblingFiles(projectFilePath, currentName);
});

// Step 8: Rename parent directory if it matches the old project name
ExecuteStep(progressDialog, stepIndex++, () =>
{
return ProjectFileService.RenameParentDirectoryIfMatches(projectFilePath, currentName, newName);
}, out projectFilePath);

// Step 8: Update references in projects that referenced this project
// Step 9: Update references in projects that referenced this project
ExecuteStep(progressDialog, stepIndex++, () =>
{
ProjectReferenceService.UpdateProjectReferences(referencingProjects, oldProjectFilePath, projectFilePath);
});

// Step 9: Re-add project to solution, preserving solution folder location
// Step 10: Re-add project to solution, preserving solution folder location
ExecuteStep(progressDialog, stepIndex++, () =>
{
SolutionFolderService.AddProjectToSolution(dte.Solution, projectFilePath, parentSolutionFolder);
projectReaddedToSolution = true;
});

// Step 10: Update using statements across the entire solution
// Step 11: Update using statements across the entire solution
ExecuteStep(progressDialog, stepIndex++, () =>
{
SourceFileService.UpdateUsingStatementsInSolution(dte.Solution, currentName, newName);
});

// Step 11: Update fully qualified type references across the solution
// Step 12: Update fully qualified type references across the solution
ExecuteStep(progressDialog, stepIndex++, () =>
{
SourceFileService.UpdateFullyQualifiedReferencesInSolution(dte.Solution, currentName, newName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Renaming Project"
Width="400"
Height="360"
Height="384"
ResizeMode="NoResize"
WindowStartupLocation="CenterOwner"
ShowInTaskbar="False">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public RenameProgressDialog(string projectName)
new ProgressStep("Updating project file"),
new ProgressStep("Updating namespace declarations"),
new ProgressStep("Renaming project file"),
new ProgressStep("Renaming sibling files"),
new ProgressStep("Renaming project directory"),
new ProgressStep("Updating project references"),
new ProgressStep("Re-adding project to solution"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;

namespace CodingWithCalvin.ProjectRenamifier.Services
Expand Down Expand Up @@ -26,6 +28,45 @@ public static string RenameProjectFile(string projectFilePath, string newName)
return newFilePath;
}

/// <summary>
/// Renames sibling files that share the project file name as a prefix.
/// For example, renaming Foo.csproj also renames Foo.csproj.user, Foo.csproj.filters, etc.
/// </summary>
/// <param name="projectFilePath">Full path to the already-renamed project file.</param>
/// <param name="oldName">The old project name (without extension).</param>
/// <returns>A list of the old file paths that were renamed.</returns>
public static IReadOnlyList<string> RenameSiblingFiles(string projectFilePath, string oldName)
{
var directory = Path.GetDirectoryName(projectFilePath);
var extension = Path.GetExtension(projectFilePath);
var newName = Path.GetFileNameWithoutExtension(projectFilePath);
var oldProjectFileName = oldName + extension;
var newProjectFileName = newName + extension;

var siblingFiles = Directory.GetFiles(directory)
.Where(f =>
{
var fileName = Path.GetFileName(f);
return fileName.StartsWith(oldProjectFileName + ".", StringComparison.OrdinalIgnoreCase);
})
.ToList();

var renamed = new List<string>();

foreach (var filePath in siblingFiles)
{
var fileName = Path.GetFileName(filePath);
var suffix = fileName.Substring(oldProjectFileName.Length);
var newFileName = newProjectFileName + suffix;
var newFilePath = Path.Combine(directory, newFileName);

File.Move(filePath, newFilePath);
renamed.Add(filePath);
}

return renamed;
}

/// <summary>
/// Renames the parent directory if its name matches the old project name.
/// </summary>
Expand Down