Topanoe
Topanoe

Reputation: 405

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?

Upvotes: 17

Views: 46944

Answers (4)

You can define any port number in the launch.json file like below (Reference code taken for Django application run)

       "args": [
            "runserver", "3300",
        ],

Upvotes: 0

Mitch Gollub
Mitch Gollub

Reputation: 452

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

Upvotes: 32

Jordan McDonald
Jordan McDonald

Reputation: 1131

Do you have to remove this when you deploy to staging or production? This doesnt seem good for anything but local dev.

Upvotes: 3

Tummala Krishna Kishore
Tummala Krishna Kishore

Reputation: 8271

In your Program.cs

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

Port number can be anything other than the specified one

Upvotes: 4

Related Questions