How to Run Azure Function App on a Different Port in Visual Studio

I am setting local host port in local.setting.json. Referring Microsoft doc

The file looks like below

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "AzureWebJobsDashboard": ""   
  },
  "Host": {
    "LocalHttpPort": 7073
  }
}

When I run/debug the solution , VS still host the app on default port (7071)

I have checked the bin directory, the local.setting.json file is geting there with above settings. Running Azure Fucntion CLI (func host start) from bin directory correctly read the port number.

Looks like VS is not using the "LocalHttpPort" port. Is there any other changes required in the settings. I have Visual Studio 2017 Preview (2)

1

11 Answers

I am using the CLI version 1.2.1, and the following Application arguments setting in Project Properties -> Debug worked for me.

host start --port 7074 --nodeDebugPort 5860

7

Update: If you're just looking to change the port, you don't have to set it through the file specified in the question. Check Thuc Nguyen answer

Original answer:

the command line takes precedence over the settings file, the problem is that VS passes an explicit port on the command line.

work around is to go through project -> properties -> Debug, then under Application arguments take control of the args. you can type host start --pause-on-error

Edit from ravinsp:

Update for .Net Core 2.0 function project:

The command line arguments you have to pass are different. You have to pass in the path to a dll in front. Like this: %AppData%\..\Local\Azure.Functions.V2.Cli\2.0.1-beta.22\Azure.Functions.Cli.dll host start --pause-on-error You can see for yourself by running the function in Visual Studio and using the process explorer to see command line args to dotnet.exe process.

edit: a word

4

Update Project Properties -> Debug to following

host start --port 7073 --pause-on-error

2

As of this version:

Azure Functions Core Tools (3.0.2912 Commit hash: bfcbbe48ed6fdacdf9b309261ecc8093df3b83f2)
Function Runtime Version: 3.0.14287.0

you only have to type start --port 7074 in the Application Arguments box

1

Correct answer for .NET Core 2.0 / .NET Standard 2.0 Azure Functions project in Visual Studio 2017 when you have installed Azure Functions Core Tools 2.x Runtime via NPM

I followed @ahmelsayed's answer and in particular, @ravinsp's comments for .net core 2.0 comments. While very helpful and putting me on the right track, they did not work for me without a crucial and non-intuitive modification so I'm adding a fresh answer.

TL;DR;

If you've used NPM to install Azure Functions Core Tools 2.x Runtime then you may need to set Project/Properties/Debug/Application Arguments to:

C:\Users\<myuserid>\AppData\Roaming\npm\node_modules\azure-functions-core-tools\bin\func.dll host start --port 8888 --pause-on-error

Long answer follows ...

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.