.Net Core build a solution

Fab picture Fab · Jun 22, 2016 · Viewed 19.1k times · Source

If you try to run from the command line in the top directory of a solution made with visual studio:

dotnet build

My solution is architectured like that:

MySolution.sln
   > src
       > MyProject1
           > project.json
       > MyProject2
           > project.json
   > test
       > MyProject.Test
           > project.json

it will fail with the following error:

Couldn't find 'project.json' in current directory

How could I build the solution without having to specify each project explicitely (and then without the related maintenance) ?

Answer

Fab picture Fab · Jun 22, 2016

.NET Core 1.0 Preview (project.json)

You can use wildcards like that from the top directory (where lies the .sln).

  • With the project.json in SolutionDir/Src/ProjectName:

    dotnet build */**/project.json

  • If project.json in SolutionDir/ProjectName:

    dotnet build **/project.json

Note: It's recommended to migrate to new csproj project format to get support and new features.

Since .NET Core 1.0 RTM

The solution is back for good.

  dotnet build solution.sln

In powershell, build all csproj file under the current directory.

foreach ($csproj in $(Get-ChildItem -Recurse . -Filter *.csproj) )
{
    dotnet build $csproj.FullName
}