问题
When I deploy my Azure Function project to my Function App based on the v2 runtime, the binding extensions my project depend on (Azure Storage in my case), are not automatically created.
I deploy my project with an extensions.csproj file on the root, but after deploying I have to manually run the following command to create a bin and obj folder at wwwroot.
dotnet build extensions.csproj -o bin --no-incremental --packages D:\home\.nuget
If I understand correctly, this should happen automatically.
回答1:
For deployment by CLI func azure functionapp publish
Function core tools use zip deployment to deploy functions, in this way, kudu doesn't build project by default. To enable the feature, set SCM_DO_BUILD_DURING_DEPLOYMENT
to true
in Application settings on portal.
As for why the default setting is false, zip deployment usually requires the content to be deployed including all related files hence there's no need to build again.
For Azure function core tools, we usually use command func extensions install
to register extensions for input/output binding when extensions are not installed automatically like we create trigger from template. This is why command func start
and func azure functionapp publish
doesn't build extensions.csproj
, extensions are supposed to be installed before we run or publish functions.
Update for DevOps deployment
With Azure pipeline, we need to build extensions.csporj
before archive files. Add a .NET Core build task, arguments are -o bin
.
If you want kudu to build project, go to Deployment Center under Platform features. Choose VSTS as a CI repository and kudu will build and deploy project for you.
回答2:
When using Visual Studio, you'll be referencing the extension packages directly from your project in order to use their attributes and other types, so Visual Studio handles the installation process, but registration still needs to be performed.
This is handled by a custom build task, added by the Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator
NuGet package, which must be explicitly referenced (this will be automatically brought in by the SDK/Visual Studio tools in a future update).
These are the steps you must follow to use the CosmosDB extension mentioned in our previous example:
1.Add a reference to the Microsoft.Azure.WebJobs.Extensions.Storage
NuGet package
2.Add a reference to the Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator
3.Build the project
For more details, you could refer to this article.
来源:https://stackoverflow.com/questions/52703296/azure-functions-with-runtime-2-binding-extensions-not-automatically-created