Hot reload and debugging breakpoints for dotnet6 in Visual Studio Code - c#

I tried what is described here e.g. updating the following to my launch.json, and the program runs.
However, my breakpoints empty out and say No symbols have been loaded for this document when I hover them.
Any suggestions?
{
// 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": "debug-hot-reload",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "dotnet",
"args": [
"watch",
"--project",
".",
"--verbose"
],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"Key": "Value"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}

You can try this solution to your issue:
Adding this line of code: <DebugType>portable</DebugType> to your "yourprojectname.csproj" file. This should be helpful to your issue.
If this doesn't work, please let me know and let's see what else can we do.

Related

ASP.NET Net 7.0 I cannot run the debugger while "watch"

This is mine:
https://imgur.com/gallery/NC5sA1i
When I run the debugger, the dotnet watch is running, but it's in the Terminal process, not the debugger process. On the red arrow, you can see the VSCode never finishes booting the debugger.
this 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": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "watch",
"launchSettingsProfile": "https",
"program": "${workspaceFolder}/website-app/bin/Debug/net7.0/website-app.dll",
"args": [],
"cwd": "${workspaceFolder}/website-app",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
and this is the tasks.json file:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/website-app/website-app.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/website-app/website-app.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/website-app/website-app.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
I'm following this tutorial:
https://youtu.be/fuBi4d7k1-M?t=1327
at 22:07, he just change the preLaunchTask: build to preLaunchTask: watch
I tried exactly what he did, but I can't figure out why my debugger is not working.
Tried on macOS and Windows, same result.
Please help.
Thanks in advance

Remote debugging with VS Code on Windows to a Raspberry Pi

I need help to setup my vscode in order to deploy and debug a dotnet application on my RPi 4 (Raspberry Pi OS x64), because I'm not able to attach the vscode debugger.
The application is correctly built and deployed on my RPi, and I can run it via ssh using the command dotnet ~/MyFirstApp/MyFirstApp.dll, but when I try to run it using the debugging function of vscode it returns the following error:
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET program, but dotnet-~/MyFirstApp/MyFirstApp.dll does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
Here all the files:
MyFirstApp.cs
Console.WriteLine("Hello, World!");
MyFirstApp.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
.vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (remote)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "RaspberryPiDeploy",
"program": "~/.dotnet/dotnet",
"args": ["~/${workspaceFolderBasename}/${workspaceFolderBasename}.dll"],
"cwd": "~/${workspaceFolderBasename}",
"stopAtEntry": false,
"console": "internalConsole",
"pipeTransport": {
"pipeCwd": "${workspaceFolder}",
"pipeProgram": "ssh",
"pipeArgs": [
"pi#192.168.2.122"
],
"debuggerPath": "~/vsdbg/vsdbg"
}
}
]
}
.vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/MyFirstApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "RaspberryPiPublish",
"command": "sh",
"type": "shell",
"dependsOn": "build",
"windows": {
"command": "cmd",
"args": [
"/c",
"\"dotnet publish -r linux-arm64 -o bin\\linux-arm64\\publish --no-self-contained\""
],
"problemMatcher": []
}
},
{
"label": "RaspberryPiDeploy",
"type": "shell",
"dependsOn": "RaspberryPiPublish",
"presentation": {
"reveal": "always",
"panel": "new",
"close": true
},
"windows": {
"command": "scp -r bin\\linux-arm64\\publish\\* pi#192.168.2.122:${workspaceFolderBasename}"
},
"problemMatcher": []
}
]
}
It is possible to apply two different types of build: Self-contained and Framework-dependent.
The Self-contained build requires to run chmod +x on MyFirstApp (thanks to #PMF's suggestion):
launch.json
{
"name": ".NET Remote Launch - Self-contained",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "RaspberryPiDeploySelfContained",
"program": "~/MyFirstApp/MyFirstApp",
"args": [],
"cwd": "~/MyFirstApp",
"stopAtEntry": false,
"console": "internalConsole",
"pipeTransport": {
"pipeCwd": "${workspaceRoot}",
"pipeProgram": "ssh",
"pipeArgs": [
"pi#192.168.2.122"
],
"debuggerPath": "~/vsdbg/vsdbg"
}
}
tasks.json
{
"label": "RaspberryPiPublishSelfContained",
"command": "sh",
"type": "shell",
"dependsOn": "build",
"windows": {
"command": "cmd",
"args": [
"/c",
"\"dotnet publish -r linux-arm64 -o bin\\linux-arm64\\publish\""
],
"problemMatcher": []
}
},
{
"label": "RaspberryPiDeploySelfContained",
"type": "shell",
"dependsOn": "RaspberryPiPublishSelfContained",
"presentation": {
"reveal": "always",
"panel": "new",
"close": true
},
"windows": {
"command": "scp -r bin\\linux-arm64\\publish\\* pi#192.168.2.122:${workspaceFolderBasename}; ssh pi#192.168.2.122 chmod +x \"${workspaceFolderBasename}/${workspaceFolderBasename}\""
},
"problemMatcher": []
}
This solution works, but, considering that it is a "self-contained" app, it requires more time to copy all the dependencies and requires more disk space.
The Framework-dependent solution requires to copy fewer files (less time and disk space to deploy and test it):
launch.json: I had to setup the args field providing the path as /home/pi/MyFirstApp/MyFirstApp.dll, I can't figure out why, but giving the path as ~/MyFirstApp/MyFirstApp.dll gives back the error Could not execute because the specified command or file was not found.
{
"name": ".NET Remote Launch - Framework-dependent",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "RaspberryPiDeploy",
"program": "~/.dotnet/dotnet",
"args": ["/home/pi/MyFirstApp/MyFirstApp.dll"],
"cwd": "~/MyFirstApp",
"stopAtEntry": false,
"console": "internalConsole",
"pipeTransport": {
"pipeCwd": "${workspaceRoot}",
"pipeProgram": "ssh",
"pipeArgs": [
"pi#192.168.2.122"
],
"debuggerPath": "~/vsdbg/vsdbg"
}
}
tasks.json
{
"label": "RaspberryPiPublish",
"command": "sh",
"type": "shell",
"dependsOn": "build",
"windows": {
"command": "cmd",
"args": [
"/c",
"\"dotnet publish -r linux-arm64 -o bin\\linux-arm64\\publish --no-self-contained\""
],
"problemMatcher": []
}
},
{
"label": "RaspberryPiDeploy",
"type": "shell",
"dependsOn": "RaspberryPiPublish",
"presentation": {
"reveal": "always",
"panel": "new",
"close": true
},
"windows": {
"command": "scp -r bin\\linux-arm64\\publish\\* pi#192.168.2.122:\"~/${workspaceFolderBasename}\""
},
"problemMatcher": []
}

How to set not to open new web browser tab in vscode when running asp.net core api project

e.g
Every time i key ctrl + f5 or ctrl + shift + f5 to rerun asp.net core api project in vscode,it'll open a new tab.
I expect just restart program without opening new tab.
updated : CLI version (recommand)
It can use dotnet watch to do it .
visul studio code (op want to merge)
If you don't want any browser tab be created,you colud go to .vscode\launch.json remove serverReadyAction and it can deal the problem.
default json :
{
// 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": [
{
//Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
}
}
]
}
just delete or mark serverReadyAction then system'll not open any web browerser tab 🤗
{
// 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": [
{
//Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
// "serverReadyAction": {
// "action": "openExternally",
// "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
//}
}
]
}
P.S
I test set launchBrowser enabled false but it not work,it'll still create new tab.
launchBrowser enabled false launch.json :
{
// 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": [
{
"launchBrowser": {
"enabled": false
},
"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}/bin/Debug/netcoreapp3.0/ServerApp.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
//Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
Visual Studio Version :
Every kind of application shows you some kind of UI, prompt, or form. Otherwise, how would user know that’s its up and running.
By default, it’s open a new tab only.
Your project template itself is web API? then how can you expect the web without the browser?
Update: I tried setting the launchBrowser to false in launchSettings.json in Visual studio 2019, it’s launching like the below images.
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false,
"launchUrl": "default",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
You are setting launchBrowser to false in wrong way, you have to do like this "launchBrowser": false. Its working fine in Asp.Net Core 3.1 API.
You can see in the taskbar
If you don't want any browser tab be created,you colud go to .vscode\launch.json remove serverReadyAction and it can deal the problem.
default json :
{
// 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": [
{
//Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
}
}
]
}
just delete or mark serverReadyAction then system'll not open any web browerser tab 🤗
{
// 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": [
{
//Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
// "serverReadyAction": {
// "action": "openExternally",
// "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
//}
}
]
}
P.S
I test set launchBrowser enabled false but it not work,it'll still create new tab.
launchBrowser enabled false launch.json :
{
// 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": [
{
"launchBrowser": {
"enabled": false
},
"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}/bin/Debug/netcoreapp3.0/ServerApp.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
//Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
after setting for vscode files and add to launch.json
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Parto.Web/bin/Debug/net5.0/Parto.Web.dll",
"args": [],
"cwd": "${workspaceFolder}/Parto.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"
}
},
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Launch - Chrome",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Parto.Web/bin/Debug/net5.0/Parto.Web.dll",
"args": [],
"cwd": "${workspaceFolder}/Parto.Web",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start \"\" \"C:/Program Files/Google/Chrome/Application/chrome.exe\" ${auto-detect-url}"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5000"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Parto.Web/Views"
}
},
and settings.json
{
"omnisharp.path": "latest",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[csharp]": {
"editor.defaultFormatter": "ms-dotnettools.csharp"
}
}
and add this to omnisharp.json
"MSBuild": {
"UseLegacySdkResolver": true}
in VS Code terminal
First dotnet build
Second dotnet run "Address of Web Project"
then after run project successfully
Launching browser by cmd.exe /C start http://localhost:5000

ASP.NET Core 3 MVC : IHost not starting browser unlike IWebHost

ASP.NET Core 3 MVC suggests using IHost instead of IWebHost (HostBuilder replaces WebHostBuilder and .NET Generic Host Settings for web apps).
Here is a section of launch.json
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
This doesn't however launch the browser for debugging locally.
OS: Linux
Editor: VSCode
For launching browser automatically, you could try follow steps below:
Upgrade VS Code to version 1.39.2
Add section below to launch.json
"serverReadyAction": {
"action": "openExternally",
"pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
},
Here is a demo full content:
{
// 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 (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp3.0/CoreJWT3_0.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"serverReadyAction": {
"action": "openExternally",
"pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
},
"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": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
,]
}

Visual Studio Code .NET Core - Launch (web) does not start the browser

I am trying to debug a .NET Core WebApi application on Red Hat Linux. But when I press F5 I get the following in the DEBUG CONSOLE and the browser does not start. Thank You
Module is optimized and the debugger option 'Just My Code' is enabled.
The program '[4657] TodoApi.dll' has exited with code 0 (0x0).
here's what's in the launch.json file
{
// 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 (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/TodoApi.dll",
"args": [],
"cwd": "${workspaceFolder}",
"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 http://localhost:5000/api/values"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
You should place 'http://localhost:5000/api/values' within the "args" section instead of appending to the "command" section.
So the code, in your case, will be something like:
"linux": {
"command": "xdg-open",
"args": "http://localhost:5000/api/values"
}

Categories

Resources