.Net Azure Function app publish does not generate a bin folder

  Kiến thức lập trình

I work a lot to migrate an azure function app from net core 3.1 to net 6. After a long time i made all the azure functions to work fine in local. The next step was to deploy the azure function. The build and publish run successfully in the pipeline but, even when the runtimes changes impacted, the azure function where not listing the azure functions in the resource in azure portal.

There were something wrong with the artifact the we were trying to publish

We make a lot of research and we realize that the bin folder was not present in the artifact generated after publish the azure function. This happens in local too with local publish from visual studio. We have another net 6 azure function that, after publish, the bin folder is present with all the dll so we are sure that is not something related to net 6

2

I found a similar issue in which the azure function is unable to generate the bin folder.

To resolve this issue, use the workaround given by @BabyGiant.

Add the below configuration in the build.targets:

 <Target Name="MakeMyDir" AfterTargets="Build">
    <MakeDir Directories="$(PublishDir)bin" />
  </Target>

the azure function where not listing the azure functions in the resource in azure portal

This happens due to various reasons. As you have migrated the function from .NET core 3.1 to .NET 6.0, the issue could be due to missing configurations or version incompatibility between the packages.

Create a sample .NET 6.0 Azure function and compare the folder structure, files, configurations and the package versions with your existing function project as @Miao Tian-MSFT mentioned in the comments.

local.settings.json:

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet"
  }
}

host.json:

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            },
            "enableLiveMetricsFilters": true
        }
    }
}

.csproj:

Check the package versions.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.4.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Create a publish profile with Release configuration and Deploy the function to Azure:

Recognized by Microsoft Azure Collective

1

I have an isolated function so I have a configured a dotnet-isolated FUNCTIONS_WORKER_RUNTIME.

According to your comment, I created two Azure Functions applications to test the issue.

One is using .NET 6 runtime. When published to folder in local visual studio, it publishes with a bin folder.

Another is using .NET 6 Isolated runtime. When published to folder in local visual studio, it publishes no bin folder.

After checking the official documentation, I found that this is by design.

Sample content files for Azure Functions in the in-process model (.NET 6) in the official documentation:

<framework.version>
 | - bin
 | - MyFirstFunction
 | | - function.json
 | - MySecondFunction
 | | - function.json
 | - host.json

Sample content files for Azure Functions in the isolated worker model (.NET 6 Isolated ) in the official documentation:

  • .azurefunctions/
  • extensions.json
  • functions.metadata
  • host.json
  • worker.config.json
  • Your project executable (a console app)
  • Other supporting files and directories peer to that executable

So, as you are using the .NET 6 Isolated runtime for your azure function project, you should not look for the bin folder. Maybe you can consider using the .NET 6 runtime instead of .NET 6 Isolated runtime to get a bin folder.

2

After a lot of research we deploy the azure app in a test resource group in azure using visual studio directly. The deploy was successful and the function app works. We confirm that the bin folder was not needed because of, using Kudo, the files deployed does not have the bin folder.

However there were some inconsistencies between the files deployed from visual studio using the test resource group and the real ones. There were two missing files:

  • X.Functions.exe
  • X.Functions.runtimeconfig.json

After a lot of differents test i realize that maybe i could use the Publish Profile that Visual Studio autogenerates using my configurations to do the publish before deployed the files in the resource. There is a way to use a publish with profile extension file using the dotnet publish command so we could include that in our pipeline.

The publish profile was named CloudPublishProfile.pubxml and the content is the next one:

<Project>
  <PropertyGroup>
    <WebPublishMethod>ZipDeploy</WebPublishMethod>
    <PublishProvider>AzureWebSite</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <LaunchSiteAfterPublish>false</LaunchSiteAfterPublish>
    <UpdateApiOnPublish>true</UpdateApiOnPublish>
  </PropertyGroup>
</Project>

The dotnet publish command task ends like this where :

- task: DotNetCoreCLI@2
    displayName: "Copy AzureFunctions build output"
    enabled: true
    inputs:
      arguments: '--configuration Release -p:PublishProfile=CloudPublishProfile --no-build --no-self-contained --output                  "$(Build.ArtifactStagingDirectory)/legacy/X.Azure.Functions"'
      command: "publish"
      publishWebProjects: false
      workingDirectory: "$(Build.SourcesDirectory)/legacy/X.Azure.Functions/"
      zipAfterPublish: true

After that the deployed files between the app deployed in the test resource (the one is working) and the real one have no differences between them. They have the exactly the same quantity and structure of files. There where only one difference remaining. The test azure function apps works and the other not 🙁

I post this as an answer because of the question itself is answered but the original problems remains.When eventually we manage to solve this i will came back to this question and i will post the update. Until that stay safe and thank you very much

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT