

Add All Project to Solution with dotnet CLI
source link: https://ardalis.com/add-all-projects-to-solution/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Add All Project to Solution with dotnet CLI
Date Published: 15 December 2022
If you need to just create a new solution file with all projects in all subfolders in it, this should work for you.
Scenario
For whatever reason, you'd like to quickly create a Visual Studio solution file that includes all of the Visual Studio (dotnet) projects in any subfolder. In my case, sometimes I've needed to do this in order to easily be able to calculate code metrics on the total of a GitHub repository or set of samples. You may just want to be able to see all of the projects in one place. It can be tedious to locate and add every csproj file in every subfolder by hand, especially in a codebase you're not familiar with.
YouTube: Add All Projects in Git Repo to Solution (and analyze them)
The dotnet sln Command
It may surprise you to learn that you can create .NET solution files from the command line. The syntax is pretty straightforward:
dotnet new sln -n Everything
In the above, the -n
flag allows you to specify the name; otherwise it will use the current foldername as a default. In my case since I wanted every project in it, I just named it Everything. The result of this command is an empty solution file named Everything.sln.
Next you just need to add all of the project files. Unfortunately there's no built-in way to do that with the dotnet sln
command, but you can easily script it. This should work from Powershell or a linux shell:
dotnet sln add (ls -r **/*.csproj)
This will recursively find .csproj
files in any subfolder and will add them to the solution using the dotnet sln add
command. With just these two commands you can easily add many Visual Studio projects to a solution file without manually adding them.
Troubleshooting
If you already have a solution file in the folder where you're running this, you just need to specify your solution file's name in the command. So if your solution file is named Everything.sln you'd run this:
dotnet sln ./Everything.sln add (ls -r **/*.csproj)
References
Recommend
-
16
Build server – client contracts with dotnet CLI Now days type safety is common within the web-world with TypeScript and on the horizon WebAssembly with .NET Core (Blazor etc). I have for a long time advocated for the importance of...
-
9
dotnet cli 5.0 新特性——dotnet tool search Intro# .NET 5.0 SDK 的发布,给 dotnet cli 引入了一个新的特性,dotnet tool search,主要用于搜索 Nuget...
-
13
These days for every web application, there has always been the need to monitor application performance, but not always do it well. Similar is the case with the .NET application, but then we found Elastic APM, which is the best solution over...
-
6
You might have just learnt about HTML, JavaScript and CSS and you have been hearing about popular JS frameworks such as Vue JS. Vue JS is one of the most loved frontend frameworks out there and you might be wo...
-
6
Enable in-memory cross project referencing for C# -> F# projects by TIHan · Pull Request #11301 · dotnet/fsharp · GitHub Copy link Contrib...
-
5
Angular CLI - request deprecated error (Solution) Aug 3 ・1 min read ...
-
13
How to Create a new Solution and Projects using dotnet CLI Date Published: 17 August 2021
-
4
Lastmile CLI: Simulate all the thingsBy Remco van Bree and Alex Hartwell
-
4
0:00 / 28:59 ...
-
8
Upgrading a 20 year old University Project to .NET 6 with dotnet-upgrade-assistant Sponsored By I wrote a Tiny Virtual Operating System
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK