Introduction
With .NET 8, Microsoft introduced a new solution file format: .slnx
. This format aims to improve solution management, making large-scale editing scenarios easier and optimizing performance for large codebases.
As mentionned earlier in March in
Chet Husk’s post
on .NET blog, Microsoft now officially supports it in their latest SDK ! 😎
Before .NET 9, the only way available to use this new format was to use the “Save As” feature on an existing .SLN file and target the SLNX format.
Now new projects can be created by default using this format, which is pretty cool 🥳
In this post, I’ll give you some good reasons to use this new format, and some hints on how to migrate an existing .sln
solution to the new .slnx
format, if you have some remaining projects using the old heavy-bloated file. 💩
Why Switch to .slnx
?
The .slnx
format offers several advantages:
- Performance Optimization: Faster loading times for large solutions.
- Simplified Editing: The format is XML-based, making it easier to edit and also integrate with third-party tools. For me this is THE real game-changer 🙏
- Better Support for Large Projects: Reduces conflicts, improves dependency management and reviewing.
Prerequisites
Before proceeding with the migration, ensure that you have:
- .NET 8 or a later version installed.
- The .NET IDE of your choice (Rider recommended lol).
- An existing
.sln
solution to migrate.
Migration Steps
1. Check Your .NET SDK Version
First, verify your SDK version by running:
dotnet --version
If you’re using an earlier version than .NET 8, update your SDK.
2. Convert the Solution to .slnx
Run the following command to perform the conversion:
dotnet sln migrate
This command:
- Converts the existing
.sln
file to.slnx
. - Preserves configurations and project references.
- Leaves the original
.sln
file intact (you can remove it after validation).
Alternatively, you can use the “Save as” option by right-clicking on your SLN file in Rider, and save it as a new SLNX. (I suppose the same option is available in VS.) But the purpose here is to show you the tool made specifically by Microsoft for this kind of task. 😉
3. Verify the Solution Integrity
Open the .slnx
file with Visual Studio or a JSON editor to ensure the structure is correct. You can also run:
dotnet build
to verify that the solution still compiles correctly.
Here is how my sample solution looked like before the migration:
And here is how it looks after:
As you can see, the new format removed a lot of noise and “useless” infos. It really focuses on the main purpose of this file, your solution projects. 💪
4. Remove the Old .sln
File (Optional)
Once you validated your migration, you can delete the old .sln
file and update your version control system :
git rm MySolution.sln
git add MySolution.slnx
git commit -m "Migrated solution to .slnx format"
Conclusion
Switching to the .slnx
format is a step toward better solution management in .NET.
By following these steps, you ensure a smooth transition and benefit from the advantages of the new format without losing compatibility, enabling better support for editing and compatibility such as CI tasks etc.
Doing this migration is, of course, not mandatory for existing projects. And the old SLN format is still supported in latest version of SDKs.
So consider using this format if you have time so spend on migrations, or if you are starting new projects 😉
As always, Happy hacking 👨💻❤️