Fix Microsoft.Extensions.DependencyModel publish clash
Error
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly
'Microsoft.Extensions.DependencyModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
Serilog raises this while reading its configuration. It is a race: last writer to out/ wins, so it only shows up after test-project or publish-order changes.
Root cause
The Dockerfile runs dotnet publish on the whole solution into a single flat out/ folder that becomes the runtime image.
The solution includes test projects. coverlet.collector ships Microsoft.Extensions.DependencyModel 8.0.2; the Host needs 10.x. Both write the same filename. When coverlet's copy wins, the host asks the CLR for assembly version 10.0.0.0 and gets 8.0.0.0.
Do not pin or add Microsoft.Extensions.DependencyModel on the Host csproj / Directory.Packages.props. That papers over the clash; the next test dependency can still overwrite out/.
Fix
- Find every test project (
*Tests*.csproj,*Test*.csproj). - Add
<IsPublishable>false</IsPublishable>beside the existing<IsPackable>false</IsPackable>(addIsPackabletoo if missing):
<PropertyGroup>
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
</PropertyGroup>
- Verify with the exact
dotnet publishfrom that repo's Dockerfile (usuallydotnet publish "<Solution>.sln" --no-restore -c Release -o out). - Confirm
out/has no test binaries: noMoq.dll, no*.Tests.dll, nocoverlet.collector.deps.json. - Confirm the host
*.deps.jsonhas a singleMicrosoft.Extensions.DependencyModelexpectation at the host version (e.g.10.0.12). - Confirm tests still build and run (
dotnet test).