vidstige
vidstige

Reputation: 13085

Can I build multiple projects with dotnet build?

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?

Upvotes: 4

Views: 7494

Answers (3)

Alper Ebicoglu
Alper Ebicoglu

Reputation: 9634

Go to the root of your solutions and run the following PowerShell (only for .NET Core projects)

$baseDir = (Get-Item -Path ".\" -Verbose).FullName
Write-Host ("Scanning *.sln files in " + $baseDir)
$solutionPaths = Get-ChildItem -Path $baseDir -Include *.sln -Recurse
Write-Host ("Total found: " + $solutionPaths.Count)
foreach ($solutionPath in $solutionPaths) {  
    Write-Host ("Building => " + $solutionPath)
    dotnet build $solutionPath
}

Upvotes: 0

arvindd
arvindd

Reputation: 346

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.

Upvotes: 6

Brandon O'Dell
Brandon O'Dell

Reputation: 1171

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.

Upvotes: 2

Related Questions