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
?
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.
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.
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.
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
In your Program.cs
try to add .UseUrls("http://localhost:5050")
Port number can be anything other than the specified one
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With