Set default project in solution for dotnet run

There appears to be no dotnet configuration file yet - would be nice to see a .dotnetconfig.json or similar, otherewise extending the SLN file to support default project for dotnet command. Following @MartinUllrich line of thinking, assuming you have Node.js installed, simply create a package.json and call npm start. This same pattern could work for other script engines as well.

package.json

{
  "name": "dotnet-run-default-project",
  "private": true,
  "version": "1.0.0", 
  "scripts": {
    "start": "dotnet run -p .\\src\\MyApplication.Web\\"
  }
}

Running Default Project

npm start


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 scripts (.bat, .sh) that call the right dotnet run -p my/project command for you without requiring you to do much typing.


If you are on a *nix system a Makefile can solve all repetitive typing problems.

I generally create a high level Makefile to shorten frequently used commands.

build:
    dotnet build
clean:
    dotnet clean
restore:
    dotnet restore
watch:
    dotnet watch --project src/Main/Main.csproj run
start:
    dotnet run --project src/Main/Main.csproj

The above commands relate to a clean architecture setup where the file structure roughly looks like the following tree.

-- root
|-- src
|    |-- Application
|    |-- Core
|    |-- Infrastructure
|    |-- Main
|-- tests
|    |-- Application.IntegrationTests
|    |-- Core.UnitTests
|    |-- Infrastructure.UnitTests
|-- API.sln
|-- Makefile

With that setup, I can run commands like

make start