TExcelTAD
Home › .NET Builds: MSBuild & NuGet › Solutions: .sln and .slnx

Solutions: .sln and .slnx

A project builds one assembly. Real products have several: a library, an app, a test project, maybe a tool. A solution groups them so that one command (or one IDE window) builds them all in the right order. For twenty years that file was the .sln format; the .NET 10 SDK makes the new XML-based .slnx the default.

Creating a solution in .NET 10

bash · try it yourself
mkdir shop && cd shop
dotnet new sln -n Shop
ls
cat Shop.slnx
dotnet new classlib -n Shop.Core -o src/Shop.Core > /dev/null
dotnet new console -n Shop.App -o src/Shop.App > /dev/null
dotnet new xunit -n Shop.Tests -o tests/Shop.Tests > /dev/null
dotnet sln add src/Shop.Core src/Shop.App
dotnet sln add --solution-folder tests tests/Shop.Tests
cat Shop.slnx
dotnet sln list
The template "Solution File" was created successfully.

Shop.slnx
<Solution>
</Solution>
Project `src/Shop.Core/Shop.Core.csproj` added to the solution.
Project `src/Shop.App/Shop.App.csproj` added to the solution.
Project `tests/Shop.Tests/Shop.Tests.csproj` added to the solution.
<Solution>
  <Folder Name="/src/">
    <Project Path="src/Shop.App/Shop.App.csproj" />
    <Project Path="src/Shop.Core/Shop.Core.csproj" />
  </Folder>
  <Folder Name="/tests/">
    <Project Path="tests/Shop.Tests/Shop.Tests.csproj" />
  </Folder>
</Solution>
Project(s)
----------
src/Shop.App/Shop.App.csproj
src/Shop.Core/Shop.Core.csproj
tests/Shop.Tests/Shop.Tests.csproj

The .slnx file is short, readable XML: one <Project Path="…"> per project, inside <Folder> elements for solution folders. Notice that dotnet sln add in SDK 10 put the two src/ projects into a /src/ solution folder on its own: by default it mirrors the directory a project lives in (--in-root adds a project at the top level instead). --solution-folder tests named the folder explicitly. Compare that with the classic format.

The classic .sln format

dotnet new sln --format sln still writes the old format, and dotnet sln migrate converts it:

bash · try it yourself
mkdir legacy && cd legacy
dotnet new sln -n Legacy --format sln > /dev/null
dotnet new classlib -n Core -o Core > /dev/null
dotnet sln Legacy.sln add Core > /dev/null
sed -n '1,12p' Legacy.sln | sed -E 's/"\{[0-9A-F-]{36}\}"$/"{GUID}"/'
dotnet sln Legacy.sln migrate
cat Legacy.slnx

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{GUID}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Debug|x64 = Debug|x64
		Debug|x86 = Debug|x86
.slnx file /home/learner/legacy/Legacy.slnx generated.
<Solution>
  <Configurations>
    <Platform Name="Any CPU" />
    <Platform Name="x64" />
    <Platform Name="x86" />
  </Configurations>
  <Project Path="Core/Core.csproj" />
</Solution>

The .sln format is a line-based text format with a GUID for every project (a new random one each time a project is added, masked here by sed) (and a "project type" GUID before it), plus a GlobalSection that lists every configuration × platform pair for every project. Merge conflicts in that section are a rite of passage. The .slnx format drops everything that can be derived: the project type comes from the file extension, configurations come from the projects. migrate kept only what it couldn't derive: the old file declared x64 and x86 platforms besides Any CPU, so it wrote a <Configurations> element for them.

.sln .slnx
Format custom text, GUIDs XML, paths only
Default in dotnet new sln up to SDK 9 SDK 10
Supported by every tool since 2002 SDK 9.0.200+, MSBuild 17.13+, Visual Studio 17.13+, Rider, VS Code C# Dev Kit
Merge conflicts frequent (GUIDs, config sections) rare

Note: Keep one solution file per folder. After migrate, both Legacy.sln and Legacy.slnx exist, and any dotnet command that has to find "the" solution fails with Found more than one solution file … Specify which one to use. Delete the old one once everyone's tools read .slnx.

Building a solution

dotnet build in a folder with one solution builds that solution. MSBuild turns the solution into a graph: every project is a node, and ProjectReference items are edges. Projects are built in dependency order, and each project is built once even if several others reference it.

bash · try it yourself
mkdir shop && cd shop
dotnet new sln -n Shop > /dev/null
dotnet new classlib -n Shop.Core -o src/Shop.Core > /dev/null
dotnet new console -n Shop.App -o src/Shop.App > /dev/null
dotnet sln add src/Shop.App src/Shop.Core > /dev/null
dotnet add src/Shop.App reference src/Shop.Core
dotnet build -nologo | grep -E '\->|Warn|Err'
Reference `..\Shop.Core\Shop.Core.csproj` added to the project.
  Shop.Core -> /home/learner/shop/src/Shop.Core/bin/Debug/net10.0/Shop.Core.dll
  Shop.App -> /home/learner/shop/src/Shop.App/bin/Debug/net10.0/Shop.App.dll
    0 Warning(s)
    0 Error(s)

Even though Shop.App was added to the solution first, Shop.Core was built first: the order comes from the reference graph, not from the solution file. dotnet add … reference (or its .NET 10 spelling dotnet reference add) wrote this into Shop.App.csproj:

xml
<ItemGroup>
  <ProjectReference Include="..\Shop.Core\Shop.Core.csproj" />
</ItemGroup>

A solution is not required to build: dotnet build src/Shop.App builds the app and, through the ProjectReference, the library too. The solution adds the projects nobody references (tests, tools) and is what IDEs open.

Solution filters

Large repos often add solution filters (.slnf, dotnet new slnf): a JSON file naming a solution and a subset of its projects, so a team can open or build only the part they work on. CI usually builds the full solution.

Test yourself

What does dotnet new sln produce with the .NET 10 SDK?

  1. A .sln file
  2. A .slnx file
  3. A Directory.Build.props
  4. A global.json

In which order does MSBuild build the projects of a solution?

  1. In the order they are listed in the solution file
  2. Alphabetically
  3. In dependency order, following ProjectReference items
  4. In parallel with no ordering

After dotnet sln Legacy.sln migrate, dotnet build fails with 'Found more than one solution file'. Why?

  1. The migration corrupted the file
  2. Both Legacy.sln and Legacy.slnx are now in the folder
  3. .slnx needs a NuGet package
  4. Solutions can't contain class libraries