Set default project in solution for dotnet run

4imble picture 4imble · Oct 10, 2017 · Viewed 13.1k times · Source

I have created a solution and a webapi project in it's own folder. I have then added the project to the solution.

I would like to be able to run dotnet run without specifying the project by setting a default (Like i would in Visual Studio)

Is this possible or not yet doable with the CLI?

Answer

Martin Ullrich picture Martin Ullrich · Oct 14, 2017

At the moment, this is not possible with dotnet run.

dotnet run does call msbuild targets to do a restore and build but queries the actually program and arguments to run from a new static evaluation, which means that even if you add custom build logic to a solution (=> the "project" being built), you don't have a chance to run custom msbuild logic to fetch these properties from other projects. (One could still hard-code relative paths to the built executable but this is very cumbersome and not very flexible)

This means the best way would be to create scipts (.bat, .sh) that call the right dotnet run -p my/project command for you without requiring you to do much typing.