Furqan Misarwala
Furqan Misarwala

Reputation: 1891

How to publish azure function from vs code?

I have installed azure-tools-vscode, but don't know exactly how to use it for publishing the Azure function:

some steps I have tried are:

Windows PowerShell
Copyright (C) 2015 Microsoft Corporation. All rights reserved.


PS D:\azurenodejsfunctions>

PS D:\azurenodejsfunctions> func azure login      

PS D:\azurenodejsfunctions> func azure account set <SubscriptionId>

PS D:\azurenodejsfunctions> func azure functionapp publish ..\azurenodejsfunctions\

Publish D:\azurenodejsfunctions contents to an Azure Function App. Locally deleted files are not removed from destination.
Getting site publishing info...
Can't find app with name "..\azurenodejsfunctions\" in current subscription.

PS D:\azurenodejsfunctions>

I tried the other way , created manually azure function app and then try:

PS D:\> func azure functionapp publish azurenodejsfunctions

Exception :
Unable to find function project root. Expecting to have host.json in function project root.

Files and folder structure,

Files and folder structure

Now mystery for me. Any ideas on why this happens & how to fix this?

Upvotes: 1

Views: 3989

Answers (1)

Brando Zhang
Brando Zhang

Reputation: 27962

According to your description and error message, if you want to publish the azure function in the visual studio code. You need firstly create a azure function in the protal, then use the func azure functionapp publish command to publish the function to azure.

I suggest you could follow below way.

1.Install the Azure Tools for Visual Studio Code.

Use ctrl+shift+p open the command and type below command:

ext install azuretoolsforvscode

2.Create azure function app.

Use ctrl+shift+p open the command and type below command:

azure:login

Azure:Create an azure function App(advanced)

enter image description here

3.Use ctrl+shift+c open command window and use below command to install the Azure Functions Core Tools.

npm i -g azure-functions-core-tools

4.Init the azure function local

Notice: The function name must as same as the function app you have created in the azure

func init yourfunctionname

5.Locate the function folder

cd yourfunctionname

6.Use the func azure login and func azure functionapp publish to publish the function

The command like this:

enter image description here

Upvotes: 1

Related Questions