I have a main directory containing all of my various .NET core solutions in subdirectories under it. Is there a way for me to publish all of these projects at once instead of opening and publishing each separately in Visual Studio?
Asked
Active
Viewed 1,718 times
1
-
Does this answer your question? [.NET Core - how does the 'dotnet publish' command work?](https://stackoverflow.com/questions/52421644/net-core-how-does-the-dotnet-publish-command-work) – gunr2171 Apr 19 '21 at 16:18
-
No. My question is more specific. That question asks generally how dotnet publish works. My question asks how to recursively publish multiple projects, possibly in different unrelated solutions, grouped in a single location. E.g. AllOfMyCSharpProjects/Project1Folder, AllOfMyCSharpProjects/Project2Folder, etc. – Jacob Archambault Apr 19 '21 at 16:30
1 Answers
1
You can do this with the dotnet command line interface.
To do this, open a PowerShell terminal and cd into the root directory containing the various projects you want to publish. From there, run the following:
$paths = Get-ChildItem -include *.csproj -Recurse
foreach($pathobject in $paths)
{
cd $pathobject.directory.fullName
dotnet publish
}
Doing this will publish every project into its default publish location, e.g. MyProjectFolder/bin/debug/netcoreapp3.1/publish.
To publish each project to a specified subdirectory, you can use the -o flag on the publish command. E.g. in the above, substitute dotnet publish -o bin\Debug\myCustomPublishFolder
for dotnet publish

Jacob Archambault
- 642
- 9
- 16