Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I designate a startup project in VS Code?

How do I designate a startup project in VS Code?

Context:

In Visual Studio, I right click a project within solution explorer and set it as startup.

However, I am not clear on how to accomplish this in VS Code.

Note:

I recently added a WebAPI project to my directory in VS Code.

like image 676
Scott Nimrod Avatar asked Oct 12 '17 09:10

Scott Nimrod


People also ask

How do I select a startup item in Visual Studio?

To change the startup itemExpand Environment, and then choose Startup. In the On startup, open list, choose what you want to happen after Visual Studio launches. You can choose from Start window (which lets you open a new or existing project), Most recent solution, or Empty environment.

How do I add startup CS to Visual Studio Code?

In Visual Studio, you can get this done by – right click on the project, and choose “ Set as Startup project" . If the project has multiple classes with Main , in project Properties, Application tab, select the class from the Startup object dropdown.


1 Answers

This maybe deserves a better answer. So let me explain. In Visual Studio Code you have to set up your startup projects all in the launch.json and the tasks.json files.

Here is a small detailed introduction:

  1. Choose a root project folder (i.e.: D:/anyfolder/myrootfolder)

  2. Create two folders for two projects in the root folder
    2.1 D:/anyfolder/myrootfolder/project1
    2.2 D:/anyfolder/myrootfolder/project2

  3. Open cmd and create two Console-Applications (I use .netcore 2.0)
    3.1 go to folders project1 and project2 using cmd (Command: cd -foldername-)
    3.2 for each of that folders execute the command: dotnet new console

  4. Open the root project folder with Visual Studio Code

  5. Add the following launch.json and tasks.json to the .vscode folder (usually the .vscode folder is generated after clicked the debug-button in VS Code)
    For More information visit:https://code.visualstudio.com/docs/editor/debugging

Sample launch.json file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch Project1",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceRoot}/project1/bin/Debug/netcoreapp2.0/project1.dll",
            "args": [],
            "cwd": "${workspaceRoot}/project1",
            "stopAtEntry": false,
            "console": "internalConsole"
        },
        {
            "name": ".NET Core Launch Project2",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "program": "${workspaceRoot}/project2/bin/Debug/netcoreapp2.0/project2.dll",
            "args": [],
            "cwd": "${workspaceRoot}/project2",
            "stopAtEntry": false,
            "console": "internalConsole"
        }
    ]
}

Sample tasks.json file:

{
    "version": "0.1.0",
    "command": "dotnet",
    "isShellCommand": true,
    "args": [],
    "tasks": [
        {
            "taskName": "build",
            "args": [
                "${workspaceRoot}/project1/project1.csproj"
            ],
            "isBuildCommand": true,
            "problemMatcher": "$msCompile"
        },
        {
            "taskName": "build",
            "args": [
                "${workspaceRoot}/project2/project2.csproj"
            ],
            "isBuildCommand": true,
            "problemMatcher": "$msCompile"
        }
    ]
}

Don't forget that I used .netcore 2.0. If you use another Target Framework you have to customize the upper sample files of course.

After all you should now see two items in right of the Play(Debug-)button:
.NET Core Launch Project1 and
.NET Core Launch Project2

This worked for me and my purposes...

like image 70
H. Senkaya Avatar answered Oct 02 '22 16:10

H. Senkaya