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?
Choose the solution node's context (right-click) menu and then choose Properties. The Solution Property Pages dialog box appears. Expand the Common Properties node, and choose Startup Project. Choose the Multiple Startup Projects option and set the appropriate actions.
Adding a project to a solution file Once you have a solution file, you can add a project to it using the sln add command, and provide the path to the project's . csproj file. This will add the project to an existing solution file in the current folder.
Things have changed since 2011, nowadays it's simpler to set the default project in a given solution, you can do it within Visual Studio environment: 1 Select any file of the target project; 2 Go to the Project menu, in the menu bar; 3 Select the option Set as Startup Project. More ...
If you need to create one, use the dotnet new command, as in the following example: The solution file to use. If this argument is omitted, the command searches the current directory for one.
From Arian Kulp's site, the way to change the default startup project for a solution is to edit the .sln file. You'll see some Project and EndProject lines.
For more information on the dotnet driver, see the .NET Command Line Tools (CLI) topic. To run the application, the dotnet run command resolves the dependencies of the application that are outside of the shared runtime from the NuGet cache.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With