Conveniently rename your csproj files
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:
git
(the executable) on your PATHcsproj
files have the same name as the folder in which they reside together with accompanying source code.sln
) in one directoryrenameproject 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
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.
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
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.
Example usage:
renameproject ModernRonin.ProjectRenamer ModernRonin.RenameProject
What will happen:
git mv
so it keeps your history intact<ProjectReference>
tags in other projects in your solution referencing the project will be adjustedpaket install
will be run, unless you specified the flag --no-paket
--build
, a dotnet build
will be run just to be totally safe that everything worked well, for very cautious/diligent people :-)Renamed <oldProjectName> to <newProjectName>
will be created automatically, unless you specified a flag --no-commit
If anything goes wrong, all changes will be discarded.
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
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.
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.
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
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.
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).
csproj
projects and I very likely never willcsproj
or "vbproj"; you can try to use it with for example fsproj
, but there has been no testing this of any kindrenameproject ModernRonin.CommonServices.* ModernRonin.Common.Services.*
- this would be very handy for the wide-spread convention to have an accompanying *.Tests
projectdotnet tool update -g ModernRonin.ProjectRenamer
and you need to come here to check whether there is a new version (or check nuget)paket
in the PATH
and the presence of dotnet-tools.json
and whether it contains an entry for paketThe 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.