'Error when trying to publish an azure function from Visual Studio
I get the following error message when I try to publish my function using Visual Studio, any idea how to fix this?
System.AggregateException: One or more errors occurred. ---> System.Exception: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details. --- 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.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.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.d__213.MoveNext() ---> (Inner Exception #0) System.Exception: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details. <---
System.Exception: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details.
===================
Solution 1:[1]
The solution was to update to the newest SDK.
Solution 2:[2]
Can you try this
Remove WEBSITE_RUN_FROM_PACKAGE setting entirely from Azure Functions Application Settings from Azure Portal.
Solution 3:[3]
This is a Visual Studio timeout issue, which means that your code and some other settings are not the key to the problem. This error occurs because Visual sets a timeout limit on the release. (The file is too large or the internet speed is unstable)
If your deployment project is not too big, you can wait until the network speed is stable before trying to run it. Of course, you can also try other deployment methods to avoid this problem, such as zip deploy.
Solution 4:[4]
None of the above worked for me. So I just re-downloaded the publish profile and imported it into VS and it worked.
Weird, but just in case none of the above worked for you. May worth try.
Solution 5:[5]
I experienced same strange problem - it was caused by error in my code -
I had #if DEBUG #else #if statement in my code, so debug on my computer worked, but publishing (with Release profile) failed.
Click on Output tab and you should see the real issue.
Solution 6:[6]
I have found a workaround since none of these things works for me. It's a little strange, so bear with me.
- Publish function to azure
- Wait for failure

- Go to Azure Portal / All Resources
- Find your failed published function app
- Click "Functions".. inside the Function
- Click refresh
- Publish again.. this time it works.
That's it..
Solution 7:[7]
Removing package deploy worked sometimes as @Sajeetharan suggested, but not always.
You should try to stop the host first on the portal. Then publish from VS, that worked me. Finally, restart the host.
Dunno why it now needs manual restarting, probably a Durable Task was running, blocking the automatic restarting.
Solution 8:[8]
If you're using Visual Studio 2022
There's a documented bug on github
Solution
1. Navigate to:
C:\Users\{{USER}}\.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\{{LATEST VERSION}}\build
2. Edit File: Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets
3. Inside file search for: _GenerateFunctionsExtensionsMetadataPostPublish
<Target Name="_GenerateFunctionsExtensionsMetadataPostPublish" AfterTargets="Publish"> <GenerateFunctionsExtensionsMetadata SourcePath="$(PublishDir)bin" OutputPath="$(PublishDir)bin"/> </Target>
Changed it to: - Remove "bin" after $(PublishDir)
<Target Name="_GenerateFunctionsExtensionsMetadataPostPublish" AfterTargets="Publish"> <GenerateFunctionsExtensionsMetadata SourcePath="$(PublishDir)" OutputPath="$(PublishDir)"/> </Target>
Solution 9:[9]
I had the same issue
But, there were no failure logs, it said
Web App was published successfully https://xxxxxxxxx/
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========
I have Visual Studio 2022, I updated it and had to rebuild the project again, after like 5 or 6 tries and restarts, and it worked.
could be the server was slow or the internet connectivity.
Solution 10:[10]
Without sharing your project on a playform like GitHub, it is really hard for us to offer specific advice,there are so many variables, so many combinations of NuGET packages and references that your project may have that conflict in such a way that will cause this error.
Especially with v2 Functions, I have experienced this issue or similar ones a number of times. One of the biggest factors with Functions is the competing concepts between v1 and v2.
When you use the Visual Studio publish wizard to create the target resource in Azure, it tends to have greater success, if you have been struggling with this for a while I suggest you follow this process, as a proof of concept if nothing else:
This advice works equally well in VS2017 and 2019
- Create a new Function Project in visual studio, in the same solution.
- Replicate the name of your original function
- Publish the function to a NEW Azure resource, use the publish wizard to create this resource.
- If publishing is successful:
- Move your original project code across to the new project
- Pay close attention to the versions of nuget packages that you want to bring across, they and their dependencies will need to be v2 compliant
- If publishing is NOT successful
- Make sure you upgrade your Visual Studio to the latest
- Make sure your Azure Tools are also upgraded to the latest
As a general rule of thumb, for general success with Azure Functions:
- Use v1 for .Net Framework projects, or if ANY of your reference projects or NuGET packages have .Net Fx dependencies. (so .Net 4+... or anything that is not .Net Core.)
Even when those dependencies target multiple projects, with Functions the deployment tends to fail as it is not able to properly detect the correct platform when evaluating the NuGET dependencies during deployment.
- Use v2 ONLY for .Net Core projects, make sure that your references are also only .Net core
Compile and publish your code incrementally, also use AzureDevOps or GitHub or other source code repositories to checkin your code often with Functions. At the early stages of a Functions project we often bring in mutliple refrences and NuGET packages and they seem to work locally but not when we deploy.
- using a source code repo makes it easy to commit changes before installing new packages and rollback if installing the package results an un-deployable code.
- It seems messy, but due to NuGet versioning, going back to the state before installing a package it not assimple as uninstalling that package, it may very easily have upgraded other packages, and in this changing Azure environment many package authors have chosen to upgrade their resources between .Net Framework and .Net Core, and not always have they done it well, or sometimes the retain some .Net framework elements that will cause conflicts in Azure Functions.
There are some interesting discussions that may help:
Solution 11:[11]
Default timeout is 100 seconds. So publish fail after 100 seconds. I had this same problem in my own code when upload blob and this is how I fix it to 5 minutes. So same code to Visual Studio fix it.
_client.Timeout = TimeSpan.FromMinutes(5);
CancellationTokenSource source = new CancellationTokenSource(TimeSpan.FromMinutes(5));
CancellationToken token = source.Token;
HttpResponseMessage responseMessage = await _client.PostAsync(url, content, token);
Solution 12:[12]
I installed the latest .NET Core (5.0) and upgraded my project to target .NET Core 5.0. When I was trying to publish my project I encountered this error. I forgot to change the 'Target Framework' to 'net5.0' in the publish window.


Solution 13:[13]
Removing the WEBSITE_RUN_FROM_PACKAGE works for me most of the times. But at times, it does not work.. Here are a few things, I make sure before I publish.
- The Azure CLI window should not be open.
- Go to File--> Account Settings. Make sure you are signed in.
- Use Visual Studio in Administrator mode.
- Delete the Publish Profile & recreate.
Solution 14:[14]
I Had Application Insights on the Service Dependencies list with a yellow flag. Since I don't use this tool, I just removed it and it fixed my publishing.
Solution 15:[15]
I deleted the publish profile and then reinstalled it and it worked.
Solution 16:[16]
I was having same problem, tried all the above solutions but didn't work. My solution was sign VS into my Azure account. If you are using Cloud Explorer, just check if you're already signed in if not just reenter your credentials.
Solution 17:[17]
This bug has wrecked my brain for so long. I have tried everything, publish to new app-services, publish locally, creating new publish profiles, nothing works. For some reason a computer gets bugged for a function and only solution for me has been to swap computer.
But I found a solution. It seems to have to do with ur local visual studio settings and deleting/changing name on your C:\Users{UserName}\AppData\Local\Microsoft\VisualStudio 17.0 or 16.0 and resetting your visual studio settings seems to do the trick to un-bug that computer.
I recommend changing the name of the folder as it contains your visual-studio IDE settings.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow



