Docker build complains it can't find nuget fallback package folder Docker build complains it can't find nuget fallback package folder docker docker

Docker build complains it can't find nuget fallback package folder


This is likely due to the obj\project.assests.json file that is generated by Visual Studio when you open the project. If you look in there, you'll find reference to your NuGet package folders in your Windows system.

e.g.

"packageFolders": {  "C:\\Users\\<UserName>\\.nuget\\packages\\": {},  "C:\\Program Files\\dotnet\\sdk\\NuGetFallbackFolder": {}},

A simple workaround is to add a step in your Dockerfile to delete the bin and obj files before it runs any restore, build or test step. One way to do that is to make use of the find program:

find -type d -name bin -prune -exec rm -rf {} \; && find -type d -name obj -prune -exec rm -rf {} \;

Using the Dockerfile from the tutorial you linked to as an example, that would look something like this:

FROM microsoft/dotnet:2.1-sdkWORKDIR /app# copy csproj and restore as distinct layersCOPY *.csproj ./RUN dotnet restore# copy and build everything elseCOPY . ./RUN find -type d -name bin -prune -exec rm -rf {} \; && find -type d -name obj -prune -exec rm -rf {} \;RUN dotnet publish -c Release -o outENTRYPOINT ["dotnet", "out/Hello.dll"]


The problem is some lingering files in your bin and obj directories, which you don't need to build your app from source. Therefore I think the best solution is to add the bin and obj directories into a .dockerignore file, which will exclude those folders from copying into your Docker context, resulting in a small performance boost. Here's what my .dockerignore file looks like for dotnet apps:

.dockerignore.env.git.gitignore.vs.vscodedocker-compose.ymldocker-compose.*.yml**/bin**/objbin/obj/


if your docker container is of the linux family, add this flag -r linux-x64 to the publish command, this flag should cover building for "(Most desktop distributions like CentOS, Debian, Fedora, Ubuntu, and derivatives)"; so the publish command should look like this RUN dotnet publish -r linux-x64 -c Release -o outfor other RIDs refer to this https://docs.microsoft.com/en-us/dotnet/core/rid-catalog