26

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) ?

Floern
  • 31,495
  • 23
  • 98
  • 115
Fab
  • 11,403
  • 3
  • 41
  • 60

4 Answers4

36

.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
}
Fab
  • 11,403
  • 3
  • 41
  • 60
  • 5
    I had to modify the answer to get it working: dotnet build **/project.json – Sean Aug 08 '16 at 08:11
  • U could use tool like flubu (fluent builder) to make things easier. More about on: http://stackoverflow.com/questions/40890522/choice-for-build-tool-msbuild-nant-or-something-else/42513062#42513062 – Stan88 Apr 19 '17 at 11:20
3

If you arrive here looking for the command to build a SLN with dotnet CLI (v3.1.X), using only CLI args, it's below.

dotnet build <PATH>/<TO>/<SLN_FILE>.sln

https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-build#arguments

derekbaker783
  • 2,174
  • 1
  • 16
  • 24
0

To add to the answer, if you are publishing the project, use dotnet publish src\MyProject1\ to publish all the files.

Publishing will include files defined to be included in project.json.

Chris Voon
  • 1,906
  • 2
  • 18
  • 11
0

With dotnet CLI 2.1, it could build the solution. Here is my config:

        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/SolutionName.sln",
                "/property:GenerateFullPaths=true"
            ],
            "problemMatcher": "$msCompile",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
Leow Kah Man
  • 415
  • 3
  • 12