Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug multiple ASP.NET Core projects in Visual Studio Code #1441

Closed
alexdima opened this issue Apr 29, 2017 · 17 comments
Closed

Debug multiple ASP.NET Core projects in Visual Studio Code #1441

alexdima opened this issue Apr 29, 2017 · 17 comments

Comments

@alexdima
Copy link

Moved from microsoft/vscode#25628
From @mdmoura


  • VSCode Version: 1.11.2
  • OS Version: Windows 10

I have the following ASP.NET Core solution (solution.sln) structure in VS Code:

.vscode
  launch.json
  tasks.json
src/
  api/
    api.csproj
  web/
    web.csproj
test/
  api.test/
    api.test.csproj    
solution.sln

I need to debug both api.csproj and web.csproj so I added the launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Api",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "${workspaceRoot}/src/api/bin/Debug/netcoreapp1.1/api.dll",
      "args": [],
      "cwd": "${workspaceRoot}/src/api",
      "stopAtEntry": false,
      "console": "internalConsole"
    },
    {
      "name": "Web",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "${workspaceRoot}/src/web/bin/Debug/netcoreapp1.1/Nupaya.Api.dll",
      "args": [],
      "cwd": "${workspaceRoot}/src/web",
      "stopAtEntry": false,
      "launchBrowser": {
        "enabled": true,
        "args": "${auto-detect-url}",
        "windows": {
          "command": "cmd.exe",
          "args": "/C start ${auto-detect-url}"
        },
        "osx": {
          "command": "open"
        },
        "linux": {
          "command": "xdg-open"
        }
      },
      "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "sourceFileMap": {
        "/Views": "${workspaceRoot}/src/api/views"
      }
    }
  ]
} 

And the following tasks.json:

{
  "version": "0.1.0",
  "command": "dotnet",
  "isShellCommand": true,
  "args": [],
  "tasks": [
    {
      "taskName": "build",
      "args": ["Api", "Web"],
      "isBuildCommand": true,
      "showOutput": "always",
      "problemMatcher": "$msCompile"
    }
  ]
}  

But when I debug it I get the following error:

MSBUILD : error MSB1008: Only one project can be specified.

I have tried different options but I always end with some kind of error some not even related with MSBUILD.

What is the proper way to debug multiple ASP.NET CORE projects in Visual Studio Code?

@DustinCampbell
Copy link
Member

The error you're getting is because your tasks.json is trying to pass two projects to "dotnet build" at the same time, which isn't supported. You would get the same error at the command line if you tried to execute "dotnet build Api Web".

If you need to build multiple projects that don't reference one another, you'll either need to execute "dotnet build" twice, or add both projects to a solution and build that. However, if one of the projects references the other, you only need to build the top-level project. So, if "Web" references "Api", you only need to build "Web".

@DustinCampbell
Copy link
Member

Given your project structure, I suppose you want to pass "solution.sln" in the args to "dotnet build" in your tasks.json.

As for debugging, is "api" a library or an executable?

@DustinCampbell
Copy link
Member

@mdmoura: Did the information I added above help at all?

@mdmoura
Copy link

mdmoura commented May 2, 2017

@DustinCampbell

I am now trying with 2 different type projects (API= DotNet Web and Seed = DotNet Console).

Not sure what do you mean with "passing solution.sln to args in dotnet build" in the context os VSCode.

For the following structure:

.vscode
  launch.json
  tasks.json
src/
  api/
    api.csproj
  seed/
    seed.csproj
test/
  api.test/
    api.test.csproj    
solution.sln

I have the following launch.json:

{
  "version": "0.2.0",
  "configurations": [    
    {
      "name": "Seed",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "${workspaceRoot}/src/seed/bin/Debug/netcoreapp1.1/seed.dll",
      "args": [],
      "cwd": "${workspaceRoot}",
      "stopAtEntry": false,
      "console": "internalConsole"
    },
    {
      "name": "Api",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "${workspaceRoot}/src/api/bin/Debug/netcoreapp1.1/api.dll",
      "args": [],
      "cwd": "${workspaceRoot}",
      "stopAtEntry": false,
      "launchBrowser": {
        "enabled": true,
        "args": "${auto-detect-url}",
        "windows": {
          "command": "cmd.exe",
          "args": "/C start ${auto-detect-url}"
        },
        "osx": {
          "command": "open"
        },
        "linux": {
          "command": "xdg-open"
        }
      },
      "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "sourceFileMap": {
        "/Views": "${workspaceRoot}/Views"
      }
    },
    {
      "name": ".NET Core Attach",
      "type": "coreclr",
      "request": "attach",
      "processId": "${command:pickProcess}"
    }
  ]
}

And the tasks.json is (following your suggestion):

{
  "version": "0.1.0",
  "command": "dotnet",
  "isShellCommand": true,
  "args": [],
  "tasks": [
    {
      "taskName": "build",
      "args": ["solution.sln"],
      "isBuildCommand": true,
      "showOutput": "silent",
      "problemMatcher": "$msCompile"
    }
  ]
}

But I get the error:
Could not find the preLaunchTask 'build'.

Any idea how to solve this?

The reason why I am trying to work with a solution instead of individual projects in VSCode is that when I work with individual projects folders I have C# intellisense problems in projects that dependes on others due to Ominsharp.

@DustinCampbell
Copy link
Member

The reason why I am trying to work with a solution instead of individual projects in VSCode is that when I work with individual projects folders I have C# intellisense problems in projects that dependes on others due to Ominsharp.

This can happen if you reference projects outside of the folder you have opened in VS Code. We've made some improvement around this behavior for the next release of C# for VS Code (#963).

Could not find the preLaunchTask 'build'.

Are you opening VS Code on an individual folder, or did you open it on the folder that contains your .vscode folder? If the currently opened folder in VS Code does not contain your .vscode folder with the tasks.json, I don't believe VS Code will find it.

@mdmoura
Copy link

mdmoura commented May 2, 2017

@DustinCampbell Any ETA for that release? I suppose it 1.1.0?

Are you opening VS Code on an individual folder, or did you open it on the folder that contains your .vscode folder?

I opened on the solution folder so I can see this in VSCode's Explorer panel:

.vscode
  launch.json
  tasks.json
src/
  api/
    api.csproj
  seed/
    seed.csproj
test/
  api.test/
    api.test.csproj    
solution.sln

@DustinCampbell
Copy link
Member

@DustinCampbell Any ETA for that release? I suppose it 1.1.0?

Correct. There is a beta available that you can try if you're interested. Use the Installing Beta Releases instructions if you'd like to try it.

@DustinCampbell
Copy link
Member

Your tasks.json looks to me like it should work. I just used dotnet new web to create a new project and allowed C# for VS Code to generate my tasks.json and launch.json file for me, and the tasks.json looks like so:

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

Pressing F5 successfully ran the build task and launched the application.

@jchannon
Copy link
Contributor

Try this also

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug Portal",
            "type": "coreclr",
            "request": "launch",
            "program": "/Users/jonathan/Projects/vq/src/VQPortal.Hosting.Self/bin/Debug/netcoreapp1.1/VQPortal.Hosting.Self.dll",
            "args": [],
            "cwd": "${workspaceRoot}",
            "stopAtEntry": false,
            "externalConsole": false
        },
        {
            "name": "Debug VQConsole",
            "type": "coreclr",
            "request": "launch",
            "program": "/Users/jonathan/Projects/vq/src/VQConsole/bin/Debug/netcoreapp1.1/VQConsole.dll",
            "args": [],
            "cwd": "${workspaceRoot}",
            "stopAtEntry": false,
            "externalConsole": false
        }
    ],
    "compounds": [
        {
            "name": "Debug VQConsole & Portal",
            "configurations": [
                "Debug VQConsole",
                "Debug Portal"
            ]
        }
    ]
}

@itmitica
Copy link

itmitica commented May 17, 2017

There's an extension I use: rozzzly-dev.vscode-prompt-debug.

Edit launch.json and replace "program" as per instructions.

First run you'll have to choose "Enter path" and replace fizzbuzz/Program.cs with fizzbuzz/bin/Debug/netcoreapp1.1/fizzbuzz.dll for each project.

Luckily, it has a command history.

I've opened an issue/request for appropriate netcore support.

@gabrielbarceloscn
Copy link

Thanks @jchannon and @DustinCampbell !
I was looking for a solution for debugging two projects at same time, and found this thread.

Steps:
a) I created a solution for build my web projects, because i´ve a windows forms project also.

b) Then on tasks.json, i´ve pointed to my solution on args value:

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

c) And on my launch.json:

{
  "version": "0.2.0",
  "configurations": [
      {
      "name": "Tcs View Web Development",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "${workspaceRoot}/Tcs.Erp.UI.Web/bin/Debug/netcoreapp2.0/Tcs.Erp.UI.Web.dll",
      "args": [],
      "cwd": "${workspaceRoot}/Tcs.Erp.UI.Web",
      "stopAtEntry": false,
      "internalConsoleOptions": "openOnSessionStart",
      "launchBrowser": {
        "enabled": true,
        "args": "${auto-detect-url}",
        "windows": {
          "command": "cmd.exe",
          "args": "/C start ${auto-detect-url}"
        },
        "osx": {
          "command": "open"
        },
        "linux": {
          "command": "xdg-open"
        }
      },
      "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "sourceFileMap": {
        "/Views": "${workspaceRoot}/Views"
      }
    },
    {
      "name": "Tcs Api Development",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program":
        "${workspaceRoot}/Tcs.Erp.Api/bin/Debug/netcoreapp2.0/Tcs.Erp.Api.dll",
      "args": [],
      "cwd": "${workspaceRoot}/Tcs.Erp.Api",
      "stopAtEntry": false,
      "internalConsoleOptions": "openOnSessionStart",
      "launchBrowser": {
        "enabled": true,
        "args": "${auto-detect-url}",
        "windows": {
          "command": "cmd.exe",
          "args": "/C start ${auto-detect-url}"
        },
        "osx": {
          "command": "open"
        },
        "linux": {
          "command": "xdg-open"
        }
      },
      "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "sourceFileMap": {
        "/Views": "${workspaceRoot}/Views"
      }
    },
    {
      "name": ".NET Core Attach",
      "type": "coreclr",
      "request": "attach",
      "processId": "${command:pickProcess}"
    }
  ],
  "compounds": [
    {
      "name": "Debug Tcs View and API Dev Mode",
      "configurations": [
        "Tcs View Web Development",
        "Tcs Api Development"
      ]
    }
  ]
}

@vnextcoder
Copy link

vnextcoder commented Nov 18, 2017

My Tasks.json looks as below . No Solution name is needed, Dotnet build just picks up the Solution from the Workspace root folder or the folder itself.

{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}

And My Launch.json looks like below . This allows various configurations to be shown in 'Debug' Window (CTRL+SHIFT+D). and you can launch all the projects one by one from the same Visual Studio Code Window.

{
   // Use IntelliSense to find out which attributes exist for C# debugging
   // Use hover for the description of the existing attributes
   // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
   "version": "0.2.0",
   "configurations": [
       
        {
            "name": ".NET Core Launch (Auth)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // If you have changed target frameworks, make sure to update the program path.
            "program": "${workspaceFolder}/Auth/bin/Debug/netcoreapp2.0/Auth.dll",
            "args": [],
            "cwd": "${workspaceFolder}/Auth",
            // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
            "console": "internalConsole",
            "stopAtEntry": false,
            "internalConsoleOptions": "openOnSessionStart",
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development",
                "ASPNETCORE_URLS":"http://localhost:5000"
              }


        },

        {
            "name": ".NET Core Launch (UI)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // If you have changed target frameworks, make sure to update the program path.
            "program": "${workspaceFolder}/UI/bin/Debug/netcoreapp2.0/UI.dll",
            "args": [],
            "cwd": "${workspaceFolder}/UI",
            // For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
            "console": "internalConsole",
            "stopAtEntry": false,
            "internalConsoleOptions": "openOnSessionStart",
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development",
                "ASPNETCORE_URLS":"http://localhost:5002"
              }
        },
        {
            "name": ".NET Core Launch (API)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // If you have changed target frameworks, make sure to update the program path.
            "program": "${workspaceFolder}/Api/bin/Debug/netcoreapp2.0/Api.dll",
            "args": [],
            "cwd": "${workspaceFolder}/Api",
             "console": "internalConsole",
            "stopAtEntry": false,
            "internalConsoleOptions": "openOnSessionStart",
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development",
                "ASPNETCORE_URLS":"http://localhost:5001"
                }
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

Visual Studio Code version below

Version 1.17.0
Commit be377c0faf7574a59f84940f593a6849f12e4de7
Date 2017-10-04T23:45:46.804Z
Shell 1.7.7
Renderer 58.0.3029.110
Node 7.9.0
Architecture x64

DotNet Version 2.0.0 and whole thing just works

@DostoevskyMF
Copy link

When I launch compounds configs the VS Code show message: The task 'build is already active.
How can I fix this?

@gregg-miskelly
Copy link
Contributor

@DostoevskyMF we aren't experts on the VS Code compound config feature, but based on your description I would guess the issue is that all of your debug configurations have "preLaunchTask": "build". You could probably fix this by making the first config have "preLaunchTask": "build", fix your build task so that it will build all of the projects, and remove it from the second. You might also be able to fix it by making multiple build tasks which are project specific, and update the preLaunchTask of each config to point at their appropriate task.

@bumblebee333
Copy link

Hi all,
Should I be able to launch multiple console apps with the changes described by @jchannon and @gabrielrb ?

I am doing this on .net 2.2. I have breakpoints in both console apps and code only breaks on one console app. This should not matter but I am running vscode on CENTOS-7.

Thanks
R

@gregg-miskelly
Copy link
Contributor

@bumblebee333 I don't know of any reasons why that wouldn't work. Rather than re purposing this issue, can you open a new issue with some repro steps (ex: what does your launch.json look like) and logging.

@bumblebee333
Copy link

bumblebee333 commented Aug 1, 2019

Sorry @gregg-miskelly I didn't mean to hijack this but my issue seemed similar. I am able to solve it by adding "externalConsole":true in launch.json for one of the console apps. The other one is set to: "console": "internalConsole". If I run into another issue I will definitely open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants