I am trying to set up my Visual Studio code to build multiple dotnet projects at run.
My task.json:
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build_task",
"suppressTaskName": true,
"args": [
"build", "${workspaceRoot}/main/project.json", "-o", "${workspaceRoot}/obj/", "--framework", "netcoreapp1.1"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}
This works. But when I add this:
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build_task",
"suppressTaskName": true,
"args": [
"build",
"-o", "${workspaceRoot}/obj/",
"${workspaceRoot}/main/project.json", "-f", "netcoreapp1.1",
"${workspaceRoot}/pluginSample/project.json", "-f", "netstandard1.6"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}
I get this error:
Unexpected value 'netstandard1.6' for option 'framework'
But when I compile it manually it works:
dotnet build -f netstandard1.6
Related
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
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.
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": []
}
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}"
}
,]
}
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"
}