NDepend Blog

Improve your .NET code quality with NDepend

.slnx The New .NET Solution XML File Format

April 23, 2024 3 minutes read

slnx Solution File Format

Visual Studio 2022 17.10 (actually in preview) will propose a new .NET solution file format with file extension .slnx.

For example for this simple solution:

Sample-Visual-Studio-Solution

The content of the .slnx file is:

Why a new Solution File Format?

For decades the .sln solution file format relied on a Microsoft proprietary file format, verbose, hardly readable, and based on GUIDs. At NDepend, given our focus on .NET tools, we’ve experienced firsthand the complexity of managing this file format effectively. Here is the content of the .sln file for the same simple solution:

We can see that solution folders are treated equally as projects and that a NestedProjects section defines the hierarchy. Also, the project configuration is duplicated for all projects. Each project is assigned a GUID, making it less user-friendly for humans.

The transition to the streamlined .slnx file format is a positive change for the entire .NET community. One concrete benefit I see is the improvement in handling solution file merge conflicts, a frequent and painful task for those on large teams. Because of GUIDs referencing other GUIDs the traditional .sln format makes resolving these conflicts nightmarish. The introduction of the new .slnx format promises significant enhancements, although XML is not the ideal format for resolving merge issues.

It echoes Microsoft’s earlier simplification of the .csproj C# project file format, which now includes only the essential information that a .NET IDE cannot infer:

What About Specific Project Configuration?

From Build > Configuration Manager…, you can adjust the UnitTests project settings to prevent it from compiling in Release mode. This is practical since tests are usually only run in Debug mode.

Project-Build-Configuration-Manager

Once changes are saved, the .slnx file content becomes:

Interestingly, when I converted a .sln file with an attached NDepend project file (.ndproj file extension) to .slnx, the resulting .slnx content was buggy. We use certain Visual Studio APIs to attach a .ndproj file to a solution, which seems to be unsupported at the moment. However, rest assured that with the official release of Visual Studio 2022 17.0, we will ensure compatibility with a new version of NDepend if needed.

How to Use .slnx File Format?

While Visual Studio 2022 17.10 remains in preview, it’s advisable to avoid using the .slnx format in production. This format may still undergo changes based on .slnx community feedback. It is not even yet mentioned in the Visual Studio 2022 Preview release note! JetBrains Rider people are also working on supporting .slnx.

To use it:

  • You need Visual Studio 2022 17.10 Preview 3.0 or higher installed.
  • In Tools > Options > Preview Features search for Use Solution File Persistence Model

slnx-Preview-Option

  • Then select the solution in the Solution Explorer panel. Then File > Save YourSolution.sln As…

Save-Visual-Studio-Solution-As

  • Saves as .slnx et voilà!

Saves-As-slnx

.slnx file extension is not yet per default associated with Visual Studio but you can bind it manually or drag and drop this file to VS 2022 Preview.

sln-slnx-side-by-side

 

Leave a Reply

Your email address will not be published. Required fields are marked *