I recently got the error: "The Function function is in error: Could not load file or assembly Microsoft.Extensions.Logging.Abstractions, Version=7.0.0.0 ..." in a solution with a function project and a library project; my csproj files looked (stripped down to the relevant part) like this:
Function.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Library\Library.csproj" />
</ItemGroup>
</Project>
Library.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
</ItemGroup>
</Project>
The problem arose when I updated Microsoft.Extensions.Logging.Abstractions to version 7 (I was updating all the imported libraries to the latest version).
This problem was an easy fix, as it only required to revert the library update, but the point is that it arose at run time, after the function was deployed; neiter the compiler, nor my unit tests highlighted it.
I'd like to write a unit (or integration) test to protect my project against this kind of problem, but I didn't figure out a solution.
Any suggestion?