diff --git a/src/CodingWithCalvin.ProjectRenamifier/Commands/RenamifyProjectCommand.cs b/src/CodingWithCalvin.ProjectRenamifier/Commands/RenamifyProjectCommand.cs
index 72a7c42..094bda0 100644
--- a/src/CodingWithCalvin.ProjectRenamifier/Commands/RenamifyProjectCommand.cs
+++ b/src/CodingWithCalvin.ProjectRenamifier/Commands/RenamifyProjectCommand.cs
@@ -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);
diff --git a/src/CodingWithCalvin.ProjectRenamifier/Dialogs/RenameProgressDialog.xaml b/src/CodingWithCalvin.ProjectRenamifier/Dialogs/RenameProgressDialog.xaml
index cfffd5b..f6eb84c 100644
--- a/src/CodingWithCalvin.ProjectRenamifier/Dialogs/RenameProgressDialog.xaml
+++ b/src/CodingWithCalvin.ProjectRenamifier/Dialogs/RenameProgressDialog.xaml
@@ -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">
diff --git a/src/CodingWithCalvin.ProjectRenamifier/Dialogs/RenameProgressDialog.xaml.cs b/src/CodingWithCalvin.ProjectRenamifier/Dialogs/RenameProgressDialog.xaml.cs
index e0e561a..6145a8a 100644
--- a/src/CodingWithCalvin.ProjectRenamifier/Dialogs/RenameProgressDialog.xaml.cs
+++ b/src/CodingWithCalvin.ProjectRenamifier/Dialogs/RenameProgressDialog.xaml.cs
@@ -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"),
diff --git a/src/CodingWithCalvin.ProjectRenamifier/Services/ProjectFileService.cs b/src/CodingWithCalvin.ProjectRenamifier/Services/ProjectFileService.cs
index f430fdf..0e9c787 100644
--- a/src/CodingWithCalvin.ProjectRenamifier/Services/ProjectFileService.cs
+++ b/src/CodingWithCalvin.ProjectRenamifier/Services/ProjectFileService.cs
@@ -1,4 +1,6 @@
+using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Xml;
namespace CodingWithCalvin.ProjectRenamifier.Services
@@ -26,6 +28,45 @@ public static string RenameProjectFile(string projectFilePath, string newName)
return newFilePath;
}
+ ///
+ /// 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.
+ ///
+ /// Full path to the already-renamed project file.
+ /// The old project name (without extension).
+ /// A list of the old file paths that were renamed.
+ public static IReadOnlyList 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();
+
+ 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;
+ }
+
///
/// Renames the parent directory if its name matches the old project name.
///