31

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

0

5 Answers 5

43

.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
}
Sign up to request clarification or add additional context in comments.

2 Comments

I had to modify the answer to get it working: dotnet build **/project.json
U could use tool like flubu (fluent builder) to make things easier. More about on: stackoverflow.com/questions/40890522/…
7

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

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

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

Comments

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.

Comments

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
            }
        },

Comments

0

I had this exact issue recently. Was using .NET Core 6.0 and have 2 projects within the same solution. In the end, after much back and forth and reading I found that the azure web service was taking the first build file that it found n the folder, so using the dotnet publish <relative path to the specific project that I am wanting to use> only build the specific project that I was wanting to use, so it only had the build file that I wanted to run, so Azure picked it up no problem.

This is almost identical to @derekbaker783 but this is on a project level, which didn't seem to be specified in many places that you can even do this, so thought I'd include this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.