Search code examples
.net.net-6.0dotnet-cli

Use dotnet build cmd to build several projects into the same output directory


I have a solution that contains about 10 projects, but I need to build a few of them into the same output directory with the same runtime. I managed to build a single project, but when I try to list another one .csproj to cmd it says that I can't specify several of them in one cmd. I can't build an .sln because I don't need all of the projects

dotnet build  MyProj\MyProj.csproj MyProj2\MyProj2.csproj --configuration Debug -r win-x64 -p:Platform=x64

=

error MSB1008: Only one project can be specified.

Solution

  • You can't do this (at least directly), as dotnet build specify the first command argument is a singular project or solution:

    PROJECT | SOLUTION

    The project or solution file to build. If a project or solution file isn't specified, MSBuild searches the current working directory for a file that has a file extension that ends in either proj or sln and uses that file.

    You can workaround by:

    1. Creating a separate solution file which will include only needed projects
    2. Calling command several times with different projects passed
    3. Use some CLI automation (basically point 2 but automated)