Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to specify localhost port in VS Code

I am building an ASP.NET Core app and am wanting to use a specific port when launching debug in VS Code. It defaults to running http:// localhost:5000. I am unable to find any setting for where I would change this. When I try to specify a port setting in the launch.json file, I am being alerted that it is not allowed. Is there a specific setting to set for specifying which port?

like image 461
Topanoe Avatar asked Apr 12 '17 01:04

Topanoe


People also ask

How do I find my localhost port Visual Studio?

For me, I was able to find it with the following steps in Visual Studio 2017: Right click on the web project, then click Properties. Click on the Debug tab. Under the Profile IIS Express, you will find the port at the App URL box.

How do I run a local server in VS Code?

Right click on a HTML file from Explorer Window & click to Open with Live Server . Open a HTML file and Right click on the editor and choose the options. Press F1 or ctrl+shift+P and type Live Server: Open With Live Server to start a server or type Live Server: Stop Live Server to stop a server.

How do I find the Visual Studio port code?

Launch VS Code Quick Open ( Ctrl+P ), paste the following command, and press enter. Port helps you check availability of a port, get an available port, or kill running process on a port from Visual Studio Code itself.


2 Answers

You can configure this from the launch.json file. You want to find the "env" property and add

"ASPNETCORE_URLS":"http://localhost:<PORT_NUMBER>"

Adjusting from the default launch.json it should look something like this:

"env": {
     "ASPNETCORE_ENVIRONMENT": "Development",
     "ASPNETCORE_URLS":"http://localhost:5001"
},

This way your port change will only affect your locally running application and you won't be adding debugging code to your production application

like image 74
Mitch Gollub Avatar answered Oct 11 '22 23:10

Mitch Gollub


In your Program.cs

try to add .UseUrls("http://localhost:5050")

Port number can be anything other than the specified one

like image 22
Tummala Krishna Kishore Avatar answered Oct 12 '22 00:10

Tummala Krishna Kishore