How to change .Net Core 2 debugger port of VSCode
Asked Answered
B

2

13

I'm using Visual Studio Code (VSCode) to code .Net Core 2.0 App and would like to use the VSCode debugger for that. I created a launch.json, which works with my frontend code, but I'd like to also debug the .Net code. However my main problem is that I am not using the default port (5000 I believe it is by default). So how can I change the port?

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": ".NET Core Launch (Management.Core)",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": ".Net Build (all)",
      "program": "${workspaceRoot}/Management.Core/bin/Debug/netcoreapp2.0/Management.Core.dll",
      "args": [],
      "cwd": "${workspaceRoot}/CpaManagement.Core",
      "stopAtEntry": false,
      "console": "internalConsole"
    },
}

I tried to add a port: 12345 but that is not an accepted property. I also tried to add args: ['-- port=12345'] but that didn't work either.

My .Net Core App launchSettings.json as the following configuration:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:8888/",
      "sslPort": 45678
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Web": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "api/values",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:12345/"
    }
  }
}

P.S. The ports displayed in the question are not exactly the ones I used but that shouldn't matter for the question itself.

Bowyer answered 28/11, 2017 at 19:39 Comment(0)
G
31

If about web application then you should in folder .vscode in launch.json file find line:

"env": {
 "ASPNETCORE_ENVIRONMENT":"Development"
},

and add after "ASPNETCORE_ENVIRONMENT":"Development", that: "ASPNETCORE_URLS":"http://localhost:xxxx" where xxxx - port that you want to use.

Gauge answered 16/3, 2018 at 11:49 Comment(3)
Where to put this env element? It doesn't work for me. The browser still opens up on default port 5000.Cystocele
Need to edit launch.json in the .vscode folder. Have a look at this screenshot -> yadi.sk/i/5rMkeFFWXmef6AGauge
Things must have changed, I found the port info in launchSettings.jsonIrrelevance
S
0

I am using Visual Studio Code 1.25 for Mac and changing the port number in launchSettings.json under Properties folder worked for me.

Succeed answered 22/7, 2018 at 3:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.