Azure / azure-functions-host

The host/runtime that powers Azure Functions
https://functions.azure.com
MIT License
1.93k stars 441 forks source link

VS publish fails with 'Metadata generation failed' #5229

Open TehWardy opened 4 years ago

TehWardy commented 4 years ago

I think i'm seeing something like these ...

https://github.com/Azure/azure-functions-host/issues/4055 https://github.com/Azure/azure-functions-host/issues/4578

Everything builds and runs fine locally. Left a working deploy-able solution on Friday, came in this morning to fix something completely unrelated and it's unable to publish.

This is what my VS output window has to say about the matter ...

1>------ Build started: Project: Workflow, Configuration: Debug Any CPU ------ 1>Workflow -> D:\tfs\clx\Dev\v3\Workflow\bin\Debug\netcoreapp2.2\bin\Workflow.dll 2>------ Publish started: Project: Workflow, Configuration: Debug Any CPU ------ 2>Restore completed in 893.78 ms for D:\tfs\clx\Dev\v3\Core.Objects\Core.Objects.csproj. 2>Restore completed in 893.07 ms for D:\tfs\clx\Dev\v3\Workflow\Workflow.csproj. 2>Restore completed in 893.31 ms for D:\tfs\clx\Dev\v3\Core.B2B.Objects\Core.B2B.Objects.csproj. 2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn\csc.exe /noconfig /unsafe- /checked- /nowarn:1701,1702,1701,1702,2008 /nostdlib+ /platform:x86 /errorreport:prompt /warn:4 /define:TRACE;DEBUG;NETCOREAPP;NETCOREAPP2_2 /errorendlocation /preferreduilang:en-US /reference: ... 2>Workflow -> D:\tfs\clx\Dev\v3\Workflow\bin\Debug\netcoreapp2.2\win-x86\bin\Workflow.dll 2>System.IO.FileLoadException: Could not load file or assembly 'Workflow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. 2> at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly) 2> at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath) 2> at System.Reflection.Assembly.LoadFrom(String assemblyFile) 2> at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons() 2> at MakeFunctionJson.FunctionJsonConverter.TryRun() 2>Error generating functions metadata 2> 2>Metadata generation failed. ========== Build: 1 succeeded, 0 failed, 2 up-to-date, 0 skipped ========== ========== Publish: 0 succeeded, 1 failed, 0 skipped ==========

Things I've tried ...

I can confirm ...

TehWardy commented 4 years ago

Ok having created a new "copy of the project" by simply telling VS to create a new azure functions project and then importing the code from the original and changing nothing ... I found that the publish profiles have the following differences ...

The broken one has these extra elements

<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<_IsPortable>true</_IsPortable>
<EnableMsDeployAppOffline>True</EnableMsDeployAppOffline>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<DeployIisAppPath>CLXDev-Workflow</DeployIisAppPath>

And for the elements that they both had I notice that there was a single key difference other than urls / key information username ect ...

<WebPublishMethod>ZipDeploy</WebPublishMethod>
<WebPublishMethod>MSDeploy</WebPublishMethod>

...

It seems that MSDeploy isn't working for Azure Functions I guess.

brettsam commented 4 years ago

Can you share what your broken project file looks like?

TehWardy commented 4 years ago

Of course ... here it is ...

<?xml version="1.0" encoding="utf-8"?>
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <PublishProvider>AzureWebSite</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish>https://clxdev-workflow.azurewebsites.net</SiteUrlToLaunchAfterPublish>
    <LaunchSiteAfterPublish>False</LaunchSiteAfterPublish>
    <ResourceId>/subscriptions/{my sub id}/resourceGroups/Dev/providers/Microsoft.Web/sites/{ResourceName}</ResourceId>
    <UserName>$CLXDev-Workflow</UserName>
    <_SavePWD>True</_SavePWD>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <MSDeployServiceURL>{ResourceName}.scm.azurewebsites.net:443</MSDeployServiceURL>
    <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
    <SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>
    <EnableMsDeployAppOffline>True</EnableMsDeployAppOffline>
    <EnableMSDeployBackup>True</EnableMSDeployBackup>
    <DeployIisAppPath>{ResourceName}</DeployIisAppPath>
  </PropertyGroup>
</Project>

This file was generated by an earlier version of the tooling for VS. I get the impression (due to a delay when I ask it to build the profile) it's trying to do the same thing even now, but for some reason that fails and so as a fallback it takes the zip route.

Is there some advantage to executing an Azure functions app directly out of a Zip package, surely that would slow execution times down having to unpack it?

brettsam commented 4 years ago

Running from zip (or officially known as "run from package") has a lot of benefits and is the recommended way to deploy function apps. You can see here for more details: https://github.com/Azure/app-service-announcements/issues/84.

Do you see any more explicit errors in the Output window in VS? You may need to change the source from the dropdown to see if there's anything useful.

TehWardy commented 4 years ago

Nothing more than I've already given you. To be honest since having this i figured out I could just delete the existing publish profile and resource in the cloud then:

Not sure how to save the generated auth info though so I can check in to the azure devops repo and have pipelines use it later.

Feels overkill, but it solved the issue.