Home:ALL Converter>Cannot publish to Azure Functions from Visual Studio 2019

Cannot publish to Azure Functions from Visual Studio 2019

Ask Time:2019-09-19T15:51:09         Author:Steve Farnaby

Json Formatter

Previously I was able to publish to Azure Functions from Visual Studio but recently I always get an error saying that publish encountered an error. It directs to a log file the contents of which is as follows:

    System.AggregateException: One or more errors occurred. ---> System.Exception: Publishing failed.
       --- End of inner exception stack trace ---
       at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
       at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
       at Microsoft.Publish.Framework.Model.DefaultPublishSteps.<>c__DisplayClass26_0.<IsBuildCompletedSuccessfully>b__2()
       at System.Threading.Tasks.Task`1.InnerInvoke()
       at System.Threading.Tasks.Task.Execute()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Publish.Framework.Model.DefaultPublishSteps.<DefaultCorePublishStep>d__23.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.Publish.Framework.ViewModel.ProfileSelectorViewModel.<RunPublishTaskAsync>d__205.MoveNext()
    (Inner Exception #0) System.Exception: Publishing failed.

System.Exception: Publishing failed.

I have tried the following:

  • Reset publish profile in Azure, create a new profile in Visual Studio and try publish again. Still same error.
  • Delete Function App in Azure and recreate it. Get new publish profile into Visual Studio and try publish again. Still same error.
  • Upgrade Visual Studio 2019 to latest Version (16.2.5) and try publish again. Still same error.

Note that I have a Azure website in the same solution and I can still publish that to Azure.

Author:Steve Farnaby,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58006236/cannot-publish-to-azure-functions-from-visual-studio-2019
Anton M :

I am very new to Azure functions but today I had a similar problem (maybe the same problem) and I found a workaround, so I hope it will work also for you.\nVisual studio publishes the function by sending (upload) a zip file to azure. Unfortunately it seems VS sets a timeout to send this file, so if it is too big or your connection is too slow in upload the publishing fails because it doesn't finish before the timeout :( \n\nThere are other ways to send the zip without VS, if you want to learn details see the link below, otherwise TL;DR just follow my simple instructions already tested below the link\n\nhttps://learn.microsoft.com/en-us/azure/azure-functions/deployment-zip-push\n\nI used the curl command and it works for me, no timeout. You can try also powershell or AZ cli but curl is really easy, just be careful to get right uid/pwd the uid in my case was \"$\"+\"project_name\" \nhere is an example, replace params with yours\n\ncurl -X POST -u your_username:your_password --data-binary @\"your_zip_path\" https://your_project_name.scm.azurewebsites.net/api/zipdeploy\n\n\nBe patient and wait till the end the upload, there is no progress bar, see network activity, if it's sending data the upload is in progress. You find all the params inside the publishing file you can download from azure, they are also in VS. For the zip file you can use the one VS wasn't unable to deploy, Vs does not remove it, in my case it was under the proj dir in obj\\Release\\netcoreapp2.1\\PubTmp\n\nP.S I have WEBSITE_RUN_FROM_PACKAGE set to 1 this setting is recommended to 1 by many ms doc, so be careful changing to 0, you might have side effects.",
2019-09-21T21:12:54
Mohit Verma :

If WEBSITE_RUN_FROM_PACKAGE is set as 1 it could cause issue with depoyment from visual studio:\n\nOpen the Azure portal and check if this is the case, if yes then set it as 0. It should work.\n\nHere is the supporting link \n\nHope it helps, if not please share the code base will try to repro at my end.",
2019-09-19T09:24:20
yy