So a few years ago I worked with Jaap Lamfers. Jaap showed me a tool to easily replace .csproject names and namespaces. This tool is named Bire.

Why you should care

Renaming files is hard. When renaming Projects in Visual Studio the Folder does not change and keeps its original name. The project path is declared in the Solution file (.sln). Not a problem when working in Visual Studio, but a minor annoyance when reviewing a pull request.

Also when renaming projects via Visual Studio, not all namespaces will change as well. And when renaming manually you need to change the references as well in the contents of the .csproject file.

Bire

Jaap encountered a problem where with microservices he needed to build and the namespaces could be changed afterward. The company used abbreviations for services, with bire he just could build and change the name afterward with a single command.

The tool of Jaap is available at Github jlamfers/bire.

I thought his tool was brilliant, but it missed the crucial documentation to make it understandable for the whole company.

🍺 Bire is pronounced as the Dutch word ‘Bier’. Bier is Dutch for beer. BiRe is an abbreviation for ‘binary replace’.

Using Bire

bire -from C:\git\source -to C:\git\target -replace this=that Something=Anything

This is an example I wrote in the Readme file. But I want to give you a more concrete example let’s imagine this folder structure. The project is in C:\git\MyCoolProject\source.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
source
 ┣ MyCoolProject.DataAccess
 ┃ ┣ ....
 ┣ MyCoolProject.DataModels
 ┃ ┣ ....
 ┣ MyCoolProject.Business
 ┃ ┣ ....
 ┣ MyCoolProject.WebApi
 ┃ ┣ ....
 ┣ MyCoolProject.Functions
 ┃ ┣ ....
 ┣ MyCoolProject.sln

Let’s say we don’t like MyCoolProject anymore and we want to rename it to MCP.

Then we can use Bire. Download the bire.exe from my GitHub release 1.

Use the following command to get MyCoolProject abbreviated to MCP.

1
bire -from C:\git\MyCoolProject\source -replace MyCoolProject=MCP 

We’re not copying the project we don’t need the -to param. You should have your repo in git to do this change safely right?

Ignoring the right files and file types

What if we would have certain files that would refer to MyCoolProject and we want them to stay that way instead of renaming MyCoolProject to MCP. For example a MyCoolProjectClient.cs class.

1
2
bire -from C:\git\MyCoolProject\source -replace MyCoolProject=MCP 
   -ignore "MyCoolProjectClient.cs|(.*(\.|\/|\\)(exe|dll|obj|bin|pdb|zip|\.git|\.vs|cache|packages))$"

Conclusion

Bire helped me a lot at some companies. Let tools help you and get grip on your time back. Let it be another tool in your toolbox. Let me know if you have used bire and liked it.