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 @@ -86,8 +86,14 @@ private void RenameProject(Project project, DTE2 dte)
// Update namespace declarations in source files
SourceFileService.UpdateNamespacesInProject(projectFilePath, currentName, newName);

// Rename the project file on disk
projectFilePath = ProjectFileService.RenameProjectFile(projectFilePath, newName);

// TODO: Implement remaining rename operations
// See open issues for requirements:
// - #21: Rename parent directory if it matches project name
// - #22: Remove and re-add project to solution
// - #23: Update project references
// - #9: Update using statements across solution
// - #11: Solution folder support
// - #12: Progress indication
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.IO;
using System.Xml;

namespace CodingWithCalvin.ProjectRenamifier.Services
Expand All @@ -7,6 +8,24 @@ namespace CodingWithCalvin.ProjectRenamifier.Services
/// </summary>
internal static class ProjectFileService
{
/// <summary>
/// Renames the project file on disk.
/// </summary>
/// <param name="projectFilePath">Full path to the current .csproj file.</param>
/// <param name="newName">The new project name (without extension).</param>
/// <returns>The new full path to the renamed project file.</returns>
public static string RenameProjectFile(string projectFilePath, string newName)
{
var directory = Path.GetDirectoryName(projectFilePath);
var extension = Path.GetExtension(projectFilePath);
var newFileName = newName + extension;
var newFilePath = Path.Combine(directory, newFileName);

File.Move(projectFilePath, newFilePath);

return newFilePath;
}

/// <summary>
/// Updates the RootNamespace and AssemblyName elements in a project file
/// if they match the old project name.
Expand Down