Categories
.NET .NET 8 .NET 9 .NET MAUI Android Blazor C# Desktop Developer F# General Getting Started Hybrid iOS macOS Mobile NuGet Preview Visual Studio Web What's New Windows Xamarin Xamarin.Forms

SLNX – XML-based Visual Studio Solution Files – No more cryptic GUIDs – How to Manage from CLI

Manage this new solution file format from the CLI using the newly released .NET CLI tool.

Comprehending the intricacies of a system often requires more than just deciphering the code itself. It also involves understanding the web of dependencies that are inextricably linked to it.

This includes navigating through solution files, project files, package references, static asset management, build configuration, and other related components.

With .NET going cross-platform, SDK-style projects have been introduced. The project files have been significantly simplified. They are now more comprehensible. Due to their XML-based nature, they can be easily modified using a basic text editor.

Nonetheless, the restructuring of the Visual Studio solution file is long overdue due to its intricate layout and obscure GUIDs.

Now, the XML-based redesigned Visual Studio solution file is being supported in the preview stage within the VS2022 IDE (v17.10 and higher) and Rider 2024.3 EAP.

The structure is easily comprehensible and can be modified using a basic text editor. The file extension is designated as slnx.

Sample Structure:

<Solution>
    <!-- List of Projects -->
    <Project Path="MyApp.csproj" />
    <Properties Name="Visual Studio">
    <!-- Support is provisionally available on Visual Studio 17.10 and later versions. -->
        <Property Name="OpenWith" Value="17" />
    </Properties>
</Solution>

To use this new format, it must first be enabled. Here are the steps to turn on the preview feature. The screenshot is provided for reference.

  • First, launch VS2022 and navigate to Options dialog (Tools menu → Options / Alt+T+O)
  • Start by entering the keyword slnx into the Search Option text field at the top left of the dialog
  • Then, on the right pane, verify the Use Solution File Persistence Model checkbox option

Now you’re good to go.

Enable Support for XML-based Solution File Format in Visual Studio 2022

The existing solution files can be saved to this new format using the Save As option from the File menu and then selecting the value of Save as type as XML Solution File (*.slnx).

In the Rider IDE, this option can be accessed via the solution file’s right-click context menu. Additionally, the SLNX file can be converted back to the classic format as well.

On later use, this slnx solution file can be opened directly within the IDE.

Version 5.11 and above of the All-in-One .NET MAUI Templates Pack comes with built-in support for this new solution format. As this feature is still in the preview stage, opting in to create a slnx-based solution file is explicit.

dotnet new mauiapp -o MyApp -slnx

This option is supported on the class library projects as well.

Support for this new solution file format with .NET MAUI project templates is also available in both VS2022 and Rider 2024.3 EAP IDEs.

Support for the new SLNX solution file format with .NET MAUI project templates within VS2022
Support for the new SLNX solution file format with .NET MAUI project templates within VS2022

Why this CLI Tool:

Though support within the VS and Rider 2024.3 EAP IDEs is now limited, official support has not yet been extended to the CLI. To deal with this constraint, a .NET CLI tool in the preview form was unveiled today to overcome this limitation.

Install:

Run the below command to install this .NET CLI tool.

dotnet tool install -g VijayAnand.Slnx

The tool to be installed is called slnx.

dotnet tool list -g

Features:

  • Create a blank solution file
  • Add or remove projects
  • Add or remove files as solution items
  • List files, projects, or both
  • Proper existence check and project file validations while adding a project to the solution
  • Configure the deploy option while adding App projects

It supports the commands listed here:

CommandDescription
newCreates an empty solution containing no projects.
addAdds a project to a solution file.
add fileAdds a file as a solution item to a solution file.
listLists all projects in a solution file.
list allLists all projects and files in a solution file.
list filesLists all files in a solution file.
removeRemoves a project from a solution file.
remove fileRemove a file from a solution file.
Commands supported by the VijayAnand.Slnx CLI tool

Usage:

The command structure is in line with the dotnet sln commands. All you need to do is use slnx instead of dotnet sln. It follows positional parameter design instead of named parameters.

Working with an implicit Solution file:

Note: This CLI tool operates implicitly even when a classic SLN file is located in the same directory. An explicit name is necessary only when multiple SLNX files exist in the same directory.

slnx new
slnx add MyApp.csproj
slnx add MyApp.csproj --deploy
slnx add file Directory.Packages.props
slnx list
slnx list files
slnx list all
slnx remove MyApp.csproj
slnx remove file Directory.Packages.props

While working with an explicit Solution file:

slnx new Test
slnx Test.slnx add MyApp.csproj
slnx Test.slnx add MyApp.csproj --deploy
slnx Test.slnx add file Directory.Packages.props
slnx Test.slnx list
slnx Test.slnx list files
slnx Test.slnx list all
slnx Test.slnx remove MyApp.csproj
slnx Test.slnx remove file Directory.Packages.props

Web References:

If you find these templates, tools, and extensions useful, kindly support the work. Add your review to the VS Marketplace. Also, add a Star to the Templates and Utilities GitHub repository where it’s actively maintained. Also, share this article with your team, inner circle, and social media channels.

And a significant part of my time is dedicated to incorporating new features into the templates pack. If you appreciate the work and wish to support the ongoing momentum, please consider sponsoring the project on GitHub here. Your support means a lot!

Happy coding. Stay connected as we continue to learn and share the experiences from this exciting journey of being a .NET developer.

By Vijay Anand E G

A software professional with over a decade long industry experience in developing products that spans across desktop, mobile, and web.

Discover more from Developer Thoughts

Subscribe now to keep reading and get access to the full archive.

Continue reading