Batch migrate .sln files to .slnx format across repositories
.NET has introduced a new solution file format called .slnx
that offers significant improvements over the traditional .sln
format:
- Better readability: XML-based structure that's human-readable
- Simplified merging: Reduces merge conflicts compared to the legacy format
- Easier parsing: Can be manipulated programmatically outside IDEs (for .NET devs, you can use microsoft/vs-solutionpersistence)
You can convert individual .sln
files to .slnx
using:
- The
dotnet sln migrate
command - Your IDE's built-in conversion tools
However, manually updating multiple repositories becomes tedious and time-consuming.
For organizations with many repositories, I recommend using the automated tool Meziantou.ProjectUpdater. This tool can update multiple git repositories simultaneously, as previously demonstrated in this post: Reduce boilerplate and maintain project consistency.
Here's how to set it up:
git clone https://github.com/meziantou/Meziantou.ProjectUpdater.git
Update the Program.cs
file to include your repositories and specify the .slnx
updater:
// TODO Update project collection builder to include your repositories
var projects = new ProjectsCollectionBuilder()
.AddGitHub(builder => builder
.AddUserProjects("meziantou")
.ExcludeArchivedProjects()
.ExcludeForks())
.Build();
await new BatchProjectUpdater
{
Logger = logger,
Projects = projects,
// https://github.com/meziantou/Meziantou.ProjectUpdater/blob/a8c83053141a75a0248f68966225a352ebf092ab/Meziantou.ProjectUpdater.Console/Updaters/SlnxUpdater.cs
Updater = new SlnxUpdater(),
OpenReviewUrlInBrowser = true,
BatchOptions = new()
{
DegreeOfParallelism = 4,
},
ProjectUpdaterOptions = new()
{
ForcePush = true,
//BranchName = _ => new BranchName("chore/migrate-to-slnx"),
},
}
.RunAsync();
Then run the console application. It will update all .sln
files to the new .slnx
format. You can also use it to update other files, such as .csproj
files, or to add new files to your repositories.
Do you have a question or a suggestion about this post? Contact me!