projectkudu / kudu

Kudu is the engine behind git/hg deployments, WebJobs, and various other features in Azure Web Sites. It can also run outside of Azure.
Apache License 2.0
3.12k stars 655 forks source link

Updating Kudu Build to support .NET Isolated Azure Functions Projects. #3503

Closed FinVamp1 closed 5 months ago

FinVamp1 commented 7 months ago

Copied from https://github.com/Azure/azure-functions-dotnet-worker/issues/1865

Trying to deploy a .NET 7 Isolated project from git sources using Deployment Center (App Service Build Service). The build succeeds, the log says that all files were successfully created and copied. But the function does not appear in the list of functions and cannot be triggered (the URL returns 404). When downloading the app's contents, the downloaded ZIP-file doesn't contain the binaries, only an empty host.json file.

The issue here is that the Github repro doesn't contain a solution and the logic for the Project file doesn't cover all Functions Project types scenarios.

when you do a deployment without the solution file, it tries to determine the environment by looking at the .csproj file to determine if it is a function app. The code for this is on kudu/Kudu.Core/Infrastructure/FunctionAppHelper.cs at df8349f71bd3c4ea9e153db7d593ffc2eb86f7fb · projectkudu/kudu (github.com) I believe. Since we are looking for "Microsoft.NET.Sdk.Functions" that does not exist in new isolated .NET function apps, I believe we should also be looking for "Microsoft.Azure.Functions.Worker.Sdk" as this is required for .NET isolated apps.

The reason it works when a solution file is present is that we have code on kudu/Kudu.Core/Infrastructure/VsSolutionProject.cs at df8349f71bd3c4ea9e153db7d593ffc2eb86f7fb · projectkudu/kudu (github.com) that looks at the solution file properties and also calls FunctionAppHelper.LooksLikeFunctionApp() that looks for the function runtime version that is always present.

I think the fix is to just add Microsoft.Azure.Functions.Worker.Sdk to the check below along with the Microsoft.NET.Sdk.Functions and it should work correctly when there is only a .csproj file.

    public static bool IsCSharpFunctionFromProjectFile(string projectPath)
    {
        return VsHelper.IncludesAnyReferencePackage(projectPath, "Microsoft.NET.Sdk.Functions");
    }

Thanks to Paul Yuknewicz and Eamon O'Reilly for the help on this issue and analysis and also to @scale-tone for the help in reproducting and raising this..

FinVamp1 commented 7 months ago

Test cases for App Service Build Status

jvano commented 5 months ago

Hi

If the problem persists and is related to running it on Azure App Service, please open a support incident in Azure: https://learn.microsoft.com/en-us/azure/azure-portal/supportability/how-to-create-azure-support-request

This way we can better track and assist you on this case

Thanks,

Joaquin Vano Azure App Service