Skip to content

Commit 7a17b22

Browse files
committed
feat(rename): rename project file on disk
- Add RenameProjectFile method to ProjectFileService - Uses full paths via Path.GetDirectoryName and Path.Combine - Preserves file extension - Returns new file path for subsequent operations - Update TODO comments with new issue references Closes #20
1 parent 881b14e commit 7a17b22

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/CodingWithCalvin.ProjectRenamifier/Commands/RenamifyProjectCommand.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,14 @@ private void RenameProject(Project project, DTE2 dte)
8686
// Update namespace declarations in source files
8787
SourceFileService.UpdateNamespacesInProject(projectFilePath, currentName, newName);
8888

89+
// Rename the project file on disk
90+
projectFilePath = ProjectFileService.RenameProjectFile(projectFilePath, newName);
91+
8992
// TODO: Implement remaining rename operations
9093
// See open issues for requirements:
94+
// - #21: Rename parent directory if it matches project name
95+
// - #22: Remove and re-add project to solution
96+
// - #23: Update project references
9197
// - #9: Update using statements across solution
9298
// - #11: Solution folder support
9399
// - #12: Progress indication

src/CodingWithCalvin.ProjectRenamifier/Services/ProjectFileService.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.IO;
12
using System.Xml;
23

34
namespace CodingWithCalvin.ProjectRenamifier.Services
@@ -7,6 +8,24 @@ namespace CodingWithCalvin.ProjectRenamifier.Services
78
/// </summary>
89
internal static class ProjectFileService
910
{
11+
/// <summary>
12+
/// Renames the project file on disk.
13+
/// </summary>
14+
/// <param name="projectFilePath">Full path to the current .csproj file.</param>
15+
/// <param name="newName">The new project name (without extension).</param>
16+
/// <returns>The new full path to the renamed project file.</returns>
17+
public static string RenameProjectFile(string projectFilePath, string newName)
18+
{
19+
var directory = Path.GetDirectoryName(projectFilePath);
20+
var extension = Path.GetExtension(projectFilePath);
21+
var newFileName = newName + extension;
22+
var newFilePath = Path.Combine(directory, newFileName);
23+
24+
File.Move(projectFilePath, newFilePath);
25+
26+
return newFilePath;
27+
}
28+
1029
/// <summary>
1130
/// Updates the RootNamespace and AssemblyName elements in a project file
1231
/// if they match the old project name.

0 commit comments

Comments
 (0)