Debugging the two project in the same solution in one time - debugging

I'm using only the Visual Studio Code. From CLI I created a solution with 2 projects.
Api
Acceptane tests
Debugging it separately work perfect, but in case when I want to debug a test and an endpoint in the same time - doesn't work.
launch.json file
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (API)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/ContentDownloader.API/bin/Debug/net6.0/ContentDownloader.API.dll",
"args": [],
"cwd": "${workspaceFolder}/ContentDownloader.API",
"stopAtEntry": false,
"requireExactSource": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
I try do it like:
dotnet run at solution/API/ here
via a Debug Test button I run debugger for particular test (this is an acceptance test, it request to the api and check the results)
at output I have:
...\dotnet\sdk\6.0.100\Microsoft.Common.CurrentVersion.targets(5100,5): warning MSB3026: can't copy "SomeSolution\API\obj\Debug\net6.0\apphost.exe" do "bin\Debug\net6.0\API.exe". The process cannot access the file '...\SomeSolution\API\bin\Debug\net6.0\API.exe' because it is being used by another process. [...\SomeSolution\API\API.csproj]
...because it is being used by another process.
I understand what it means :) but I have no idea or found a way to solve my problem,
I tried to write my own task / launch.json, but all without success
Please advise

Related

Unable to debug a TypeScript testing framework using Visual Studio Code

I am not able to get debugging working on VSCode for a testing framework using WebdriverIO . Only this message is displayed: - Waiting for the debugger to disconnect.
However, I am able to get debugging up and running for a TS code one time. If I am starting my machine once, and then again, it is giving same issue as - Waiting for the debugger to disconnect.
Below is the launch.json file:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [{
"type": "node",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"outputCapture": "std",
"name": "Launch Program",
"program": "${workspaceRoot}/node_modules/#wdio/cli/bin/wdio.js",
"args": ["${workspaceRoot}/build/main/config/wdio.conf.js"],
"preLaunchTask": null,
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"resolveSourceMapLocations": [ //code to avoid 'Could not read sourcemaps' issues
"${workspaceFolder}/**",
"!**/node_modules/**"
]
}]
}
Console-log stack-trace:
C:\Program Files\nodejs\node.exe .\node_modules#wdio\cli\bin\wdio.js
C:\Automation\angular_ui-auto-framework/build/main/config/wdio.conf.js
Debugger attached.   Execution of 1 workers started at
2022-12-21T15:25:32.199Z   [2022-12-21 20:55:32:902] - DONE - File
'c:\Automation\angular_ui-auto-framework\src\osr_ui-automation\Results\testReport.json'
is deleted successfully    Waiting for the debugger to disconnect...
I have faced similar problems with latest version of the vscode. I had to downgrade to nodejs 16lts and downgrade vscode to 1.57 and using below launch.json working fine so far.
{
"name": "Start Spec",
"type": "node",
"request": "launch",
"args": ["wdio.conf.js", "--spec", "${file}"],
"cwd": "${workspaceFolder}",
"autoAttachChildProcesses": true,
"program": "${workspaceRoot}/node_modules/#wdio/cli/bin/wdio.js",
"console": "integratedTerminal"
}

How do you configure visual studio code to run compiled Go code when using Run/Run&Debug (F5/CTRL+F5) VS code options?

I have installed the following task to compile my Go project following this blog post: https://robertbasic.com/blog/build-and-run-golang-projects-in-vs-code/
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build Go",
"type": "shell",
"command": "go build",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Now I can compile the project using Terminal>Run build task
For running and debugging, I have created:
launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"cwd": "${workspaceRoot}",
"args": [],
"env": {}
}
]
}
But it does not work, I get the following message:
package .: no Go files in /usr/home/username/projects/my_app/.vscode
Process exiting with code: 1 signal: false
Visual Studio Code under FreeBSD12.1 (probably not relevant).
What do I have to do to get the program running when using F5/CTRL+F5?
Any tip including recommended help section or blog entry is welcomed.
Assuming my main package is at the root folder of the workspace, I always define the same .vscode/launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}",
"env": {},
"args": []
}
]
}
From there, I can press F5 from anywhere/any file, and the debug session simply starts.

How to setup an auto watch run for .NET Core 3.1 projects using Visual Studio Code?

I need to setup an auto restart when some source code file modifies.
I'm using VS Code with Dotnet Core 3.1 to develop a web api.
When debug starts I can see my REST Api published in http://localhost:5001/api/entities, but if I change a model or something else, I need to restart the debug to see the changes.
I've tried to start the project with dotnet watch run on terminal and attatch the debug to process, but I would like to know if is possible to config something in the project to start all debugs with dotnet watch enabled.
I know this an old question, but I found a solution.
I used Marco's solution and added this to my tasks.json:
"options": {
"cwd": "${workspaceFolder}/yourproject/"
}
So the final solution is :
tasks.json
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/yourproject/yourproject.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile",
"options": {
"cwd": "${workspaceFolder}/yourproject/"
}
}
launch.json
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "watch",
"program": "${workspaceFolder}/yourproject/bin/Debug/net5.0/yourproject.dll",
"args": [],
"cwd": "${workspaceFolder}/yourproject",
"stopAtEntry": false
}
Yes this is totally possible.
In VS Code, open your tasks.json, which should be located in the .vscode folder.
In there you should find a tasks array.
The easiest way is to simply add "watch" to just edit the build task:
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"build",
"${workspaceFolder}/delete.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
]
Since "build" is the default task, when pressing F5 and startig debugging, this will always start a dotnet start build, when debugging. The key takeaway is to add watch into the args array.
If you want to have a dedicated task for that, you can add one in the tasks.json:
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"${workspaceFolder}/delete.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
}
And in your launch.json you can set this task as the preLaunchTask:
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "watch",
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/delete.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
}
]
I have created a small test project using dotnet new console to try this out locally, hence the delete.dll filename. Please make amendments as neccesary.
shameless plug, i've forked and updated dotnet auto attach vs code extension & made it to my liking dotnet watch

Don't see projectname.dll for process being debugged in Visual Studio Code

I'm just learning VS Code and Angular, I've been following a tutorial online and trying to debug. After I start the debugger it asks me what process to attach too from a drop down list it provides.
According to the debugger, I should see a 'DatingApp.API.dll' process like the one in the tutorial here, as I've named my project the same as in the tutorial.
but what I see below doesn't have the .dll name, just -bash id
now I get this when I select .Net Core Attach in the debug section, instead of the .Net Core Launch (web) option
When I select .Net Core Launch (web) it automatically attaches to the app, but my question is why don't I see the process name 'DatingApp.API.dll' as an option and see '-bash 1730' instead?
'-bash 1730' is the process so I can connect using it, I'm just curious why it doesn't name it 'DatingApp.API.dll'?
Here is my launch.json file
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/DatingApp.API/bin/Debug/netcoreapp2.2/DatingApp.API.dll",
"args": [],
"cwd": "${workspaceFolder}/DatingApp.API",
"stopAtEntry": false,
"launchBrowser": {
"enabled": true
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]}
It's a little tricky, if you type in the search DatingApp.API it will show you DatingApp.API.exe as the only result, or at least that's what I got when tried. You can attached to it too.
And Voilá! Now you can debug your C# app.

Visual Studio Code - Debugging

I downloaded the Visual Studio Code, but I don't know how to configure the debugger.
I am learning programming and i don't know how to configure it?
someone help me with this problem?
This is what you need to configure.
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch app.js",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "app.js",
// Automatically stop program after launch.
"stopOnEntry": true,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Environment variables passed to the program.
"env": { }
},
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 5858
}
]
}
You need to be more specific with your question.
What kind of code are you debugging?
Right now Visual Studio Code has debugging support for Node.js (JavaScript and TypeScript) on all platforms, experimental support for mono (C# and F#) on OS X and Linux, and soon ASP.NET 5.
If you are using one of those, you should be able to start using debugging features.
For more information, here is a direct link to the official debugging documentation: https://code.visualstudio.com/Docs/debugging
If you are coding with php you can follow these step
You can copy and paste code:
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]

Resources