I have two projects with common root opened in visual code. First is .net core webapi. Second is frontend on react/redux etc. Now when I want to run application I need to manually from console run 'npm start' and then run webapi from visual code. How can I achieve this with configuration of vs code?
At then end I want that after clicking debug I will have recompiled and deployed webapi and rebuild and same with frontend app. Then open browser in desired page.
There is an idea that I can run some script that would handle that, but I would prefer do it with pure vs code configuration.
I think that I need to modify my launch.json file. Don't know how though.
This is launch.json https://pastebin.com/9a66n3Rx
"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}/server/bin/Debug/netcoreapp2.0/webapi.dll",
"args": [],
"cwd": "${workspaceFolder}/server",
"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": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
Frontend app is in "${workspaceFolder}/client" folder
Related
I am attempting to get VS Code to launch an asp.net mvc core website utilizing a specific port number. I would like to set this via the VS Code launch.json, and NOT utilize the appsettings.json files. I have referenced multiple websites that list a number of options, but none work other than using the appsettings.json file. Setting "ASPNETCORE_URLS":"https://localhost:5050" does not work, nor do setting the arguments.
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/WAPI.Foundation/bin/Debug/netcoreapp3.1/WAPI.Foundation.dll",
"args": [ ],
"cwd": "${workspaceFolder}/WAPI.Foundation",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)",
"uriFormat": "index.html"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS":"https://localhost:5050"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
] }
I have referenced among others: VSCode launch ASP.NET Core app on a specific port
The trick was to set the launch.json configuration command line "args" "--urls" property like so. I did not modify the "env" variables as described in other posts.
"configurations": [
{
"name": ".NET Core Launch (web)",
...
"args": ["--urls","https://localhost:44304;http://localhost:6000"],
"env": {
"ASPNETCORE_ENVIRONMENT": "Local"
},
...
}
]
I found the answer here: Launch specific URL in an ASP.NET Core app in VSCode when running the app.
Google searches on 'vs code setting port number' did not return this specific result, but search for 'vs code set url to run on' brought it right up.
I'm trying to debug a Vue website I'm writing in VSCode and Chrome.
When I put a breakpoint in the data() { return {...} } function it stops on it, but if I try to put it in a method in a Vue file or a JS service, once I launch Chrome through the debug config the breakpoints become unbound. Does anyone have any ideas about how to keep the breakpoints bound?
This is my config file:
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome",
"request": "launch",
"type": "pwa-chrome",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/client/meet-for-lunch/src",
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/*"
}
},
{
"type": "node",
"request": "launch",
"name": "Debug server",
"runtimeExecutable": "nodemon",
"program": "${workspaceFolder}/server/bin/www",
"restart": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"skipFiles": [
"<node_internals>/**"
]
}
]
}
I'm including the debug config for the server because in works.
Here is an example of a method I'm trying to debug (from the Vue file), I put a break point at this.error = null . The method runs normally so I expect it to stop at the breakpoint :
methods: {
async login() {
try {
this.error = null;
const response = await AuthenticationService.login({
email: this.email,
password: this.password
})
this.$store.dispatch('setToken', response.data.token)
this.$store.dispatch('setUser', response.data.user)
}
catch (err) {
console.log(`An error has occured: ${JSON.stringify(err.response)}`)
this.error = err.response.data.error
}
}
}
I'm also trying to debug my service:
login(credentials) {
return Api().post('/login', credentials)
}
The Api object just creates the Axios request
Thanks,
Ben
https://www.codegrepper.com/code-examples/javascript/vuejs+vscode+unbound+breakpoint
After a whole day of searching this solved my problem
{
"version": "0.2.0",
"configurations": [
{
"name": "WSL Chrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/src",
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/*",
"webpack:///src/*": "${webRoot}/*"
}
}
]
}
When I had Unbound Breakpoints in VSCode I ended up needing to start the process with the --inspect or --debug-brk=5858 flag. Beyond that, launch.json gave me lots of trouble, and these resources helped
https://code.visualstudio.com/docs/nodejs/nodejs-debugging
https://code.visualstudio.com/docs/nodejs/debugging-recipes
https://github.com/microsoft/vscode-recipes/tree/master/nodemon
https://code.visualstudio.com/docs/typescript/typescript-debugging
launch.json examples:
{
"type": "node",
"request": "attach",
"name": "Node: Nodemon",
"processId": "${command:PickProcess}",
"restart": true,
"protocol": "inspector",
},
{
"name": "Launch tests via NPM",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script", "testDebug"
],
"port": 5858
}
package.json
"scripts": {
"start": "NODE_PATH=./src DEBUG=express:* NODE_ENV=dev nodemon -w src --ext ts --exec node --inspect -r tsconfig-paths/register -r ts-node/register src/index.ts",
"testDebug": "NODE_ENV=test ts-mocha --debug-brk=5858 --paths -p tsconfig.json",
}
},
Well, it's not really an answer but I've restarted my Node server a couple of (more) times and now it stops at the breakpiont. I hope that the problem doesn't return. Now he doesn't show the value of the variables for some reason but I guess that's another problem.
Thanks for the help :)
Ben
I had the same issue in my vueJS project. Something to try before making any changes to files etc which solved it for me:
In the ClientApp/App folder: 1.Delete the node_modules folder 2.Delete the package-lock.json file 3.Open a cmd prompt for your ClientApp/App folder 4.Use the cmd "npm i"
This final step will reinstall all your node-modules. The issue I had must've been a conflicting node-module.
As of May 2022...
A note if you're using vscodium and firefox you need to install firefox-devtools directly from the marketplace: https://marketplace.visualstudio.com/items?itemName=firefox-devtools.vscode-firefox-debug
Beyond that the launch.json config is standard:
{
"name": "Vue:Client",
"type": "firefox",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}/src",
"pathMappings": [
{
"url": "file://",
"path": ""
}
]
},
The extension suggested I insert those pathMappings.
See https://github.com/firefox-devtools/vscode-firefox-debug/issues/267
I want to debug my Kotlin Spring boot application after moving from Java to Kotlin, but the launch.json of Kotlin has different configurations than Java's, for example we're using profiles to switch between the environments, and when I add "args": "-Dspring.profiles.active=dev" I'm getting Property args is not allowed. And in the debug console I'm getting
Internal error: java.lang.IllegalArgumentException: io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.42.Final:compile is not a properly formed Maven/Gradle artifact
[ERROR] java.util.concurrent.CompletionException: java.lang.IllegalArgumentException: io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.42.Final:compile is not a properly formed Maven/Gradle artifact
Here's my current Kotlin configs:
{
"version": "0.2.0",
"configurations": [
{
"type": "kotlin",
"request": "launch",
"name": "Kotlin Launch",
"projectRoot": "${workspaceFolder}",
"mainClass": "path.to.my.Application",
"args": "-Dspring.profiles.active=dev" // <--- showing error
}
]
}
For comparison, here's my java launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Debug (Launch) - Current File",
"request": "launch",
"mainClass": "${file}",
"args": "-Dspring-boot.run.profiles=dev"
},
{
"type": "java",
"name": "Debug (Launch)",
"request": "launch",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"mainClass": "path.to.my.application",
"projectName": "spring",
"args": "--spring.profiles.active=dev",
"vmArgs": "-Dspring.profiles.active=dev"
}
]
}
What are the correct configs for Kotlin if I want to use profiles or args?
I have a dot net core 2 project that I develop on a Windows box, push to my linux box, then remote debug via vsdbg. Everything is working, except that the vscode window for selecting the process (via ${command:pickRemoteProcess}) pops up before the preLaunchTask starts.
My prelaunch task stops the program on my linux remote box, compiles my project, pushes it to the box, then restarts it on the linux box.
How can I delay the processId ${command:pickRemoteProcess} task until the preLaunchTask is completed?
Example task:
{
"label": "remotePush",
"command": "cmd",
"type": "shell",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "dedicated",
"showReuseMessage": true
},
"args": [
"/C ${workspaceFolder}/remotePublish.bat"
],
"problemMatcher": [
"$msCompile"
]
}
Example launch:
{
"name": "Remote Testing",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickRemoteProcess}",
"preLaunchTask": "remotePush",
"pipeTransport": {
"pipeProgram": "C:\\plink.exe",
"pipeArgs": ["-T", "administrator#myHost"],
"debuggerPath": "~/vsdbg/vsdbg",
},
"justMyCode": false,
"sourceFileMap": {
"/home/administrator/sites/mySite": "${workspaceRoot}"
}
}
I'm trying to setup debugging on OSX environment using .NET Core RC2 and Visual Studio Code. The following error is given when trying to run the debugger.
Couldn't find 'project.json' in current directory
Currently I've setup launch.json (see below) and chosen .NET Core Launch (web) in Visual Studio Code.
As my project is in a folder called Core and sharing space with two other folders my structure looks like this.
Structure
--.vscode
------ launch.json
------ tasks.json
-- Core
-- Core.Data
-- Core.Service
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/Core/bin/Debug/netcoreapp1.0/Core.dll",
"args": [],
"cwd": "${workspaceRoot}/Core",
"stopAtEntry": false
},
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/Core/bin/Debug/netcoreapp1.0/Core.dll",
"args": [],
"cwd": "${workspaceRoot}/Core",
"stopAtEntry": false,
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open",
"args": "-a chrome ${auto-detect-url}"
},
"linux": {
"command": "xdg-open"
}
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processName": "<example>"
}
]
}
Folder structure
I needed to add this code
tasks.json
"options":{
"cwd": "${workspaceRoot}/Core"
}
None of the answers helped me. I just specified the whole path to project.json and it began to work fine.
tasks.json
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}\\project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]}
So, for this particular question it would be
"args": [
"${workspaceRoot}\\Core\\project.json"
],
I ran into this problem as well. I was able to fix it by specifying the content root for the WebHostBuilder in the entry point for the application. Make sure your entry point method looks something like this:
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
The important part of that code is:
.UseContentRoot(Directory.GetCurrentDirectory())
This tells the host where to find your site assets, including project.json and your MVC views.
On Ubuntu 16.10, I went into the tasks.json file and changed the \\ to / in the single args property like below:
"${workspaceRoot}\\project.json"
to
"${workspaceRoot}/project.json"
After that it worked flawlessly. Below is my entire tasks.json (it is from a dotnet core starter project)
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}/project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
}
]
}