33

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.

===================

Recusiwe
  • 1,594
  • 4
  • 31
  • 54
  • I'm running into a [similar issue](https://stackoverflow.com/questions/59357765/publish-single-file-release-fails-for-wpf-net-core-3-1-application) at the moment in Visual Studio 2019 - though I'm trying to publish to folder in my case. I'm still trying to track down what is causing this, but I've tried this so far in my case: 1.) Clear NuGet cache, 2.) Remove bin and obj folders 3.) Created a new folder profile Also, what do you see in the output log file? Anything useful? – VirtualValentin Dec 17 '19 at 12:07
  • Have you tried to deploy it through Git via `Deployment Center ` – pavle Dec 21 '19 at 22:12
  • if any of the suggestions below doesn't work. restart the VS2019 and rebuild, publish. – Emil Jan 16 '21 at 02:51

23 Answers23

20

Can you try this

Remove WEBSITE_RUN_FROM_PACKAGE setting entirely from Azure Functions Application Settings from Azure Portal.

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • 2
    This worked for me. I'm not sure if it's related to it 'restarting' the Azure Function when the environment changes are made or if it's a blocking configuration though. – Justin Neff Apr 03 '20 at 13:59
  • 1
    In my case, i removed the attached Azure account (or profile) to visual studio and added it back. It worked for me and i was able to publish my Azure Function. – Muhammad Zeeshan Tahir Apr 19 '22 at 08:35
  • Justin Neff reminded me that the first thing you should try is closing and then reopening the solution. VS publish feature was refusing to recognize a new reference, so I tried "turning it off and then on again", which of course worked. – fartwhif Feb 23 '23 at 21:19
11

I have found a workaround since none of these things works for me. It's a little strange, so bear with me.

  1. Publish function to azure
  2. Wait for failure enter image description here
  3. Go to Azure Portal / All Resources
  4. Find your failed published function app
  5. Click "Functions".. inside the Function

enter image description here

  1. Click refresh
  2. Publish again.. this time it works.

That's it..

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Tim Davis
  • 524
  • 6
  • 17
9

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.

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • I've had succes deploying it using zipdeploy. However, when I check App content, it is updated, but when I run the function, it seems to run the old version? – Recusiwe Dec 15 '19 at 01:56
  • @Recusiwe What the 'run old version' mean? Do you mean the version of azure function was been changed?Does zip deploy solved this problem? – Cindy Pau Dec 16 '19 at 02:31
  • With "old version" I mean the last version I was able to publish from VS, not the zip-deployed one. The app content contains the code from the deployed zip, but it doesn't run it. It runs an old version. – Recusiwe Dec 16 '19 at 04:31
  • @Recusiwe Which function version you are using now? Which IDE you are using now? And what the assembly of your project?(the `.csproj` file) I faced similar error before, it seems a assembly problem that time. Sometimes this error occur only in Visual Studio 2019. You can try to use Visual Studio 2017 to see whether this exception still exsit. If you are using Visual Studio 2017, do you use Resharper? I am trying to reproduce your error and meet a similar one, but I am not sure this is related to your situation. – Cindy Pau Dec 17 '19 at 07:19
  • Function app v. 2 and Visual Studio 16.4.1 – Recusiwe Dec 17 '19 at 19:02
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.

vjirovsky
  • 208
  • 3
  • 5
5

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.

Joe Park
  • 77
  • 1
  • 6
4

I deleted the publish profile and then reinstalled it and it worked.

Timothy G.
  • 6,335
  • 7
  • 30
  • 46
  • That's what worked for me (after trying or investigating many of the other answers here that pre-date this Sept. 2021 answer). I'm wondering if the fact I moved my local project from one folder to another on my hard drive was an issue here; not sure. In the Visual Studio 2022 Publish dialog, use the More actions dropdown and select Delete from there. I first tried Restore, re-signing-into my Azure account, and it seemed to change things a bit, but in the end it still failed with the same error. Delete and then re-add (which was fairly easy; I didn't need to re-add a lot of info) worked. – StackOverflowUser Feb 22 '23 at 08:00
4

I had the same issue

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.

Ramil Aliyev 007
  • 4,437
  • 2
  • 31
  • 47
2

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.

klenium
  • 2,468
  • 2
  • 24
  • 47
2

If you're using Visual Studio 2022

There's a documented bug on github

enter image description here

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>
Dwain Browne
  • 792
  • 7
  • 12
  • 1
    That's definitely a documented Bug, but appears to be an answer to resolve error: "The path C:\{PROJECTDIR}obj\Release\netstandard2.0\PubTmp\Out\bin does not exist." I think many folks who find this StackOverflow Question are here due to matching the error: "System.Exception: Publish has encountered an error. We were unable to determine the cause of the error. Check the output log for more details." – StackOverflowUser Feb 22 '23 at 07:53
1

The solution was to update to the newest SDK.

Recusiwe
  • 1,594
  • 4
  • 31
  • 54
0

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

  1. Create a new Function Project in visual studio, in the same solution.
    • Replicate the name of your original function
  2. Publish the function to a NEW Azure resource, use the publish wizard to create this resource.
  3. 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
  4. 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:

  1. 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.

  2. 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:

Chris Schaller
  • 13,704
  • 3
  • 43
  • 81
0

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);
MeanGreen
  • 3,098
  • 5
  • 37
  • 63
JARMO
  • 1
0

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.

  1. The Azure CLI window should not be open.
  2. Go to File--> Account Settings. Make sure you are signed in.
  3. Use Visual Studio in Administrator mode.
  4. Delete the Publish Profile & recreate.
0

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.

Carlos Araujo
  • 414
  • 3
  • 7
0

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.

0

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.

Fyll
  • 1
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 30 '22 at 11:48
0

I put attention, when I have got this message, code on Azure updated well. Probably issue with some timeouts, when VS do not receive signal from web.

zzfima
  • 1,528
  • 1
  • 14
  • 21
0

My reason for this error for me was that I lost my subscriptions to Azure in Visual Studio 2019. In Server Explorer I had to reset my subscriptions and acquire a new token.

Bill
  • 1,423
  • 2
  • 27
  • 51
0

I got this error today. Same message anyway. In my case it was that the publish target had changed to an older, no longer existing instance. This value is set in a drop-down list at the top of the publish tab in visual studio. It's just to the left of the Publish button.

JerryM
  • 910
  • 6
  • 9
0

In my case, the link between the Azure Function app and storage was missing.

Make sure that the "AzureWebJobsStorage" app setting is provided for the Azure function app.

https://learn.microsoft.com/en-us/azure/azure-functions/functions-app-settings

0

mine, problem was I created function app name as kelum-func-app-test initially. then I deleted it and created as kelumfuncapptest it works for me :)

Kelum
  • 1,745
  • 5
  • 24
  • 45
0

in case none of the above answers work, try to relogin your microsoft account credentials

Clrk
  • 1
  • 1
-1

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.

Properties: Target Framework

Publish: Target Framework

Chris Schaller
  • 13,704
  • 3
  • 43
  • 81
DawnBlaze
  • 1
  • 1
  • 2