Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I build multiple projects with dotnet build?

Tags:

.net-core

Can I somehow build multiple projects with one root project.json file (or otherwise)? For example, one library, one test project, and one command line? If so, how?

like image 700
vidstige Avatar asked Feb 06 '23 23:02

vidstige


2 Answers

I may be one year late in answering, but may be it is still useful for somebody who lands here after this.

dotnet build no longer uses project.json, instead uses *.csproj. And dotnet build can now take a directory name as an argument, and uses the *.csproj within that directory for the build. This being the case, the easiest way to build from a top-level-directory goes like this:

Assuming the structure of your projects is:

src
  |
  + -- proj1
  |
  + -- proj2
  |
  + -- proj3
  |
  .
  .

Just go to the top-level directory (src in this case), and type this:

Get-ChildItem -exclude ".vscode" | %{Write-Host -ForegroundColor DarkMagenta "Building $_..."; dotnet build $_;}

I normally use PowerShell within VSCode, and hence you see the -exclude ".vscode" and PowerShell commands Get-ChildItem (aliased also as simply 'dir') and Write-Host.

Hope this helps.

like image 198
arvindd Avatar answered Feb 23 '23 01:02

arvindd


If all of your projects are stored in a structure like this :

<root>/src/Project1
<root>/src/Project2

then you can use a single command with a globbing pattern to build all of the projects at once:

dotnet build src/**/project.json

From what I am aware of, you'll still need individual project.json files for each project though.

like image 24
Brandon O'Dell Avatar answered Feb 23 '23 01:02

Brandon O'Dell