Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default project in solution for dotnet run

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?

like image 428
4imble Avatar asked Oct 10 '17 20:10

4imble


People also ask

How do I change the startup project in C#?

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.

How do I add a .csproj file to a solution?

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.

How to set the default project in Visual Studio?

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 ...

How do I create a DotNet solution file?

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.

How to change the default Startup project for a solution?

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.

How do I run a DotNet application?

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.


2 Answers

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.

like image 63
Martin Ullrich Avatar answered Sep 18 '22 19:09

Martin Ullrich


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 
like image 31
nilobarp Avatar answered Sep 17 '22 19:09

nilobarp