Seems Azure Functions does DLL cleanup to make the deployment smaller, since during deployment most of the files are already present, so you need to turn off that cleanup using <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
in your project file, which will prevent the cleanup from running. There is another setting called FunctionsPreservedDependencies
that is meant to allow you to opt-in DLLs that you want to preserve, but I couldn't get it to work for me.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<!-- necessary to use > OpenIdConnect 6.10.2-->
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1"/>
<PackageReference Include="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.15.0"/>
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.15.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>