Skip to content

New Visual Studio Solution File Format

Photo by Jonny Lew: https://www.pexels.com/photo/selective-focus-photography-of-gray-and-blue-moth-perched-on-brown-surface-1212755/

Yes, you read that right! Visual Studio is recreating its solution files, which have remained unchanged throughout my 15 years in this industry and I think this is great and anticipated improvement.

What is a solution file?

That is a great question. A Visual Studio solution file (.sln extension) is a important part of the Visual Studio development environment. It serves as a container for one or more projects and provides a way to organize and manage multiple projects within a single solution. The solution file maintains information about the projects it contains, including references between projects, build configurations, and other settings. Solution file defines what are the required projects for that software solution.

Before we dive deeper into changes and what are the benefits of all of this. Lets see what the solution files currently looks like. This is example solution file of a .NET project, that contains two different projects. Project “NewSolutionTest” which is exe and project “ClassLibrarySample” which is a class library.

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.34804.81
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NewSolutionTest", "NewSolutionTest.csproj", "{DEBBB424-C9E3-4D85-9DA9-6CEB32E1C746}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrarySample", "..\ClassLibrarySample\ClassLibrarySample.csproj", "{4852924D-5F81-4568-8737-7CBA247B98FD}"
EndProject
Global
	GlobalSection(ExtensibilityGlobals) = postSolution
		SolutionGuid = {8EC94C32-B913-427F-8FC0-C05A830BE7CF}
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{4852924D-5F81-4568-8737-7CBA247B98FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{4852924D-5F81-4568-8737-7CBA247B98FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{4852924D-5F81-4568-8737-7CBA247B98FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{4852924D-5F81-4568-8737-7CBA247B98FD}.Release|Any CPU.Build.0 = Release|Any CPU
		{DEBBB424-C9E3-4D85-9DA9-6CEB32E1C746}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{DEBBB424-C9E3-4D85-9DA9-6CEB32E1C746}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{DEBBB424-C9E3-4D85-9DA9-6CEB32E1C746}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{DEBBB424-C9E3-4D85-9DA9-6CEB32E1C746}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal

Solution file basically contains list of all the project files (.csproj) that are related to this solution and some global settings. Minimum Visual Studio version and current version are also listed on top.

This solution file structure has three big issues:

  1. Visual Studio version number is on top
  2. Project references has weird GUID’s
  3. It is hard to maintain/merge

The first issue is the version number. The information is quite irrelevant and if you re-create solution files with never version of Visual Studio, you will get different version number on top. With Git this can cause unnecessary file changes, because the version number changes.

Second problem is those weird GUID’s. They are automatically created by Visual Studio. If you have two different feature branches, that both adds new projects into solution file, you can really easily get merge conflicts because of those GUID’s. We have all seen some nasty merge conflicts caused by these solution files.

Lastly these files are hard to maintain, because they are automatically generated and they don’t have any known structure (xml/yaml/json).

Solution X to the rescue

Microsoft has released a new solution file format as a preview. This solution file extension is slnx. In Visual Studio they call it a “Solution File Persistence Model”, which doesn’t sound that sexy. Actually it sounds really boring. I think it should be called SolutionX, but that might be already registered trademark… Any way this new solution file structure is available as a preview feature in Visual Studio 2022 17.10.0 Preview 3.0. To be able to create these new solution files, you need to enable the preview feature from Visual Studio settings

Use Solution File Persistence Model…

After enabling the preview feature you can “Save As” any existing solutions as slnx files. The new structure of the same solution file as above example looks like this

<Solution>
  <Project Path="..\ClassLibrarySample\ClassLibrarySample.csproj" Type="Classic C#">
    <Configuration Solution="Debug|*" Project="*|*|NoBuild" />
  </Project>
  <Project Path="NewSolutionTest.csproj" Type="Classic C#" />
</Solution>

Woah! What the hell.

No GUID’s and no Visual Studio versions! The new solution file seems to use XML as its markdown language. This is actually pretty neat choice and look at the size of that thing. It has lost like 80% of the weight of old solution file.

The type attribute says “Classic C#” for a .NET 8.0 projects, which sounds a bit weird. I think they might be recreating the csproject files also? The solution file also contains the Configuration element. This was not present until I tried to do some changes on Visual Studio to see how the solution file reacts. I think i set the ClassLibrarySample project as NoBuild mode, so that’s why that line is in there. Without any changes the project reference looks like what NewSolutionTest.csproj line holds. Super neat and simple format.

Summary

The new Visual Studio solution format is still in preview, but it will greatly reduce merge conflicts in solution files, which I think is one of the main reasons behind this reform. You can start using this feature today by enabling the preview feature and saving new copies of your existing solution files, but as this is still in preview, the format may change.

Tags:

Leave a Reply

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