ModernRonin / ProjectRenamer

Conveniently rename your csproj files
Other
155 stars 14 forks source link
csharp csproj csproj-tooling dotnet paket rename renameproject utility

renameproject

CI Status NuGet NuGet PRs Welcome

Summary

How often have you felt the need to rename or move a C# (or VB) project? If you have come here, then you know that the most important existing IDE for C#, Visual Studio, does not really support this scenario very well.

This tool takes care of this for you, provided your use-case follows a set of fairly common practices:

Get it

renameproject is intended to be used as a global dotnet tool. (You could install it as a local tool, too, but given what it does this does not really make a lot of sense.)

You install it by executing:

dotnet tool install -g ModernRonin.ProjectRenamer

Update it

If there is a new version out, you can update renameproject with

dotnet tool update --global ModernRonin.ProjectRenamer

When I publish a new version, I always post at my blog under the renameproject tag, aside from updating this readme here.

Release History

2.2.1:

2.2.0:

2.1.5:

2.1.4:

2.1.3:

2.1.2:

2.1.1:

2.1.0:

2.0.0:

1.0.1:

1.0.0: initial release

Use it

You use it from the command line, in the directory of your solution:

renameproject <oldProjectName> <newProjectName>

The project names include neither path nor extension (.csproj). renameproject will find your project just by the name, no matter how deeply it might be hidden in your directory structure. It must be linked into the solution, though.

Simple rename

Example usage:

renameproject ModernRonin.ProjectRenamer ModernRonin.RenameProject

What will happen:

If anything goes wrong, all changes will be discarded.

Move

Since version 2.1.0, the tool also allows you to move projects. To do this, you prefix the new name with a relative folder.

Here's an example:

renameproject ModernRonin.ProjectRenamer src/ModernRonin.ProjectRenamer

If you want to move a project from somewhere in a subfolder into the root of the solution, prefix the new name with ./.

For example, to revert the change from the previous example you'd do:

renameproject ModernRonin.ProjectRenamer ./ModernRonin.ProjectRenamer --project-extension=.vbproj

Rename and Move combined

You can also move and rename in one operation like

renameproject ModernRonin.ProjectRenamer src/ModernRonin.RenameProject

However, there is a caveat: git interprets this not as rename, but as delete and create and thus you will loose the history of your project file. Thus, I recommend to do such things in two passes.

Exclude Directory

In some situations, for example if your repository contains a separate solution with separate projects in a subdirectory, you want to exclude a directory completely from being looked at by the project reference update mechanism. In that case, you can specify that directory with the optional --exclude argument.

Use with VB projects

Since version 2.2.0, you can rename Visual Basic projects now, too, thanks to a PR from @fsbflavio:

renameproject ModernRonin.ProjectRenamer ModernRonin.RenameProject --project

Help

For details about available arguments and flags/options and some example calls, you can also use

renameproject help

to get help about the available flags.

Limitations

renameproject has a few limitations. Some of them are hard limitations, meaning they are unlikely to go away, others are soft limitations, meaning they exist only because I simply have not gotten round to fix them yet. I
do not really have a lot of free time to spend on this, but am totally open to PRs (hint hint).

Hard Limitations

Soft Limitations

License

The license is Creative Commons BY-SA 4.0. In essence this means you are free to use and distribute and change this tool however you see fit, as long as you provide a link to the license and share any customizations/changes you might perform under the same license.