That is why you should always use the project (and not the solution) for your Dotnet Publish Command! So I was helping a some nice development teams with their CI/CD pipeline on GitHub deploying on an Azure App service, or so called Web App. things went well until they wrote and pushed their unit tests . (Well not everyone is doing Test Driven Development, but at least they write tests!). So long sorry short they got this error and they could not figure out what can be wrong.
Beautiful right ?
Could not load file or assembly ‘Microsoft.Extensions.DependencyModel
does not say anything actually about the error. and the wroth thing is that is works on your local machine! so what can be wrong it is probably Azure that did suddenly with App services! But hey Microsoft did made all of oss creasy with their windows server updates that suddenly broke our application at the past many times but maybe not this time!
But back to our main discussion in a case of pipeline (GitHub, Azure devOps and etc. ) docker file or even dotnet CLI you are going to run a publish command like this :
You can instead of project file give the solution file but then if you added a unit test project maybe dotnet picks up the wrong project (in this case the unit test) and publish that one! make you a few hours of headache!
# syntax=docker/dockerfile:1FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-envWORKDIR /app# Copy csproj and restore as distinct layersCOPY *.csproj ./RUN dotnet restore# Copy everything else and buildCOPY ../engine/examples ./RUN dotnet publish -c Release -o out# Build runtime imageFROM mcr.microsoft.com/dotnet/aspnet:3.1WORKDIR /appCOPY --from=build-env /app/out .ENTRYPOINT ["dotnet", "aspnetapp.dll"]