I have an ASP.NET Core 6 app deployed in Azure AppService. After I updated Serilog.AspNetCore
to 7th version it started crashing with:
Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=7.0.0.0
(issue occurs only in AppService, locally everuthing works fine)
I suspect that deployment process cleans up dll's from .NET SDK similar to Azure Functions deployment flow. In Azure Functions this issue can be resolved with
<FunctionsPreservedDependencies Include="Microsoft.Extensions.Logging.Abstractions.dll" />
or
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
Is there something similar for AppService?
Note: After downgrading the package to 6th version, everything works fine
Note 2: I don't have access to
Advanced Tools
, so cannot verify what files are being deployed (restricted by my company's DevOps)
Edit: Here's my csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<UserSecretsId>1bcc1cf7-6fce-4196-9bb5-a7aa29a04078</UserSecretsId>
<RootNamespace>MyApp</RootNamespace>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.13" />
<PackageReference Include="Serilog.Sinks.Splunk" Version="3.7.0" />
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MyApp.AppCore\MyApp.AppCore.csproj" />
</ItemGroup>
</Project>
Turns out it wasn't App Service's fault, but .NET publishing (when publishing multiple project it messes up dependency versions sometimes):
Solution in my case was to add <IsPublishable>false</IsPublishable>
to all test projects. Foolproof way of doing it is to add Directory.Build.targets
file containing this to the repository's root:
<Project>
<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
<IsPublishable>false</IsPublishable> <!-- Workaround for https://github.com/dotnet/sdk/issues/11953#issuecomment-770434716. Try removing after .NET 8 migration -->
</PropertyGroup>
</Project>