where does the "Unable to find fallback package folder" nuget error come from, when building project in a dockerfile?
Asked Answered
C

7

18

When building, from a dockerfile, I get this:

/usr/share/dotnet/sdk/3.1.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error MSB4018: The "ResolvePackageAssets" task failed unexpectedly. [/src/test/test.fsproj]
/usr/share/dotnet/sdk/3.1.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error MSB4018: NuGet.Packaging.Core.PackagingException: Unable to find fallback package folder '/usr/local/share/dotnet/sdk/NuGetFallbackFolder'. [/src/test/test.fsproj]
/usr/share/dotnet/sdk/3.1.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error MSB4018:    at NuGet.Packaging.FallbackPackagePathResolver..ctor(String userPackageFolder, IEnumerable`1 fallbackPackageFolders) [/src/test/test.fsproj]
/usr/share/dotnet/sdk/3.1.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error MSB4018:    at Microsoft.NET.Build.Tasks.NuGetPackageResolver.CreateResolver(IEnumerable`1 packageFolders) [/src/test/test.fsproj]
/usr/share/dotnet/sdk/3.1.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error MSB4018:    at Microsoft.NET.Build.Tasks.NuGetPackageResolver.CreateResolver(LockFile lockFile) [/src/test/test.fsproj]
/usr/share/dotnet/sdk/3.1.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task) [/src/test/test.fsproj]
/usr/share/dotnet/sdk/3.1.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash) [/src/test/test.fsproj]
/usr/share/dotnet/sdk/3.1.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task) [/src/test/test.fsproj]
/usr/share/dotnet/sdk/3.1.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups() [/src/test/test.fsproj]
/usr/share/dotnet/sdk/3.1.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore() [/src/test/test.fsproj]
/usr/share/dotnet/sdk/3.1.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [/src/test/test.fsproj]
/usr/share/dotnet/sdk/3.1.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/src/test/test.fsproj]
/usr/share/dotnet/sdk/3.1.102/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(234,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/src/test/test.fsproj]

Build FAILED.

A more readable version is this:

The "ResolvePackageAssets" task failed unexpectedly. [/src/test/test.fsproj]
NuGet.Packaging.Core.PackagingException: Unable to find fallback package folder '/usr/local/share/dotnet/sdk/NuGetFallbackFolder'. [/src/test/test.fsproj]
   at NuGet.Packaging.FallbackPackagePathResolver..ctor(String userPackageFolder, IEnumerable`1 fallbackPackageFolders) [/src/test/test.fsproj]
   at Microsoft.NET.Build.Tasks.NuGetPackageResolver.CreateResolver(IEnumerable`1 packageFolders) [/src/test/test.fsproj]
   at Microsoft.NET.Build.Tasks.NuGetPackageResolver.CreateResolver(LockFile lockFile) [/src/test/test.fsproj]
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task) [/src/test/test.fsproj]
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash) [/src/test/test.fsproj]
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task) [/src/test/test.fsproj]
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups() [/src/test/test.fsproj]
   at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore() [/src/test/test.fsproj]
   at Microsoft.NET.Build.Tasks.TaskBase.Execute() [/src/test/test.fsproj]
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/src/test/test.fsproj]
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/src/test/test.fsproj]

Build FAILED.

This is a WORKING dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as build

WORKDIR /src/
COPY . /src/
RUN dotnet build -c Release -o /app test/test.fsproj

FROM build AS publish
RUN dotnet publish -c Release -o /app --no-restore test/test.fsproj

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 as final

WORKDIR /app
COPY --from=publish /app .

CMD ["dotnet", "test.dll"]

the project Test.fsproj has dependencies to other projects, but I simplified it here to show what doesn't work:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as build

WORKDIR /src/
COPY test/test.fsproj ./test/
COPY test/common/libraries/mathematics/mathematics.fsproj ./test/common/libraries/mathematics/
RUN dotnet restore test/test.fsproj

COPY . /src/
RUN dotnet build -c Release -o /app test/test.fsproj

FROM build AS publish
RUN dotnet publish -c Release -o /app --no-restore test/test.fsproj

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 as final

WORKDIR /app
COPY --from=publish /app .

CMD ["dotnet", "test.dll"]

this version doesn't work. What I am trying to do is to make a restore, by copying the main project and its dependencies, matching the folders layout, so that docker can make one layer that stays in the cache and doesn't constantly restore nuget packages. being in a lockout area, I depend on sim cards for internet right now and re-downloading nuget packages at every build is a complete waste.

I do not understand the nuget error I am getting. The restore works and then the build, right after fails.

Crotch answered 24/3, 2020 at 16:17 Comment(0)
A
25

Had the same issue. After some Googling I found this nice issue: https://github.com/dotnet/dotnet-docker/issues/2050

To recap the answer there: if you have already built the project outside of Docker, then you will have output folders which will get copied into the Docker build environment causing this problem.

The solution is then to add a .dockerignore file which prevents this from happening. Something small like this should do the trick:

# directories
**/bin/
**/obj/
**/out/

# files
Dockerfile*
**/*.md
Aftermath answered 1/12, 2021 at 9:40 Comment(2)
You absolutely right! That was my case. Saved me a lot of hours! In my case I have been building from Windows, and I had an error from linux container about C:\Program Files (x86)\Microsoft\Xamarin\NuGet\ which is ridiculous. Your post explains it right away and fix is working.Uttermost
Or just delete the bin/obj in docker and rebuild again....Veronicaveronika
V
8

TL;DR

I encountered the same problem. And It took me 2 days to solve.

In visual studio Tools-> Nuget Package Manager->Package Manager Setting->Package source

There is an offline package source location. If the folder that defined as offline package source is not found, you'll encounter this error.

To solve this error, you've two options:

  1. Create the missing folder with its offline packages in it or
  2. Remove the offline location reference.

To remove the offline location reference go to C:\Program Files (x86)\NuGet\Config\ and delete the package source configuration file then everything will be fine

Voltage answered 25/10, 2022 at 8:39 Comment(2)
Create the missing folder - this solved the issue here.Vulcanite
Deleting the unnessary config files solved my error messageCommutable
H
5

Multiple things are coming to my mind.

###1: Edit csproj with the below tag:

  <PropertyGroup>
    <RestoreFallbackFolders>clear</RestoreFallbackFolders>
  </PropertyGroup>

###2: Update Dockerfile.

The dotnet sdk does not have the error folder.

root@bd6d24a2e56b:/# cd /usr/local/share/dotnet/sdk/NuGetFallbackFolder
bash: cd: /usr/local/share/dotnet/sdk/NuGetFallbackFolder: No such file or directory

Add a RUN command under FROM:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as build
RUN mkdir -p /usr/local/share/dotnet/sdk/NuGetFallbackFolder
Hose answered 25/3, 2020 at 14:3 Comment(1)
it fails differently now: it is claiming to not find the dependencies of the subprojects. for example, the mathematics subproject is dependent on ta-lib. during the restore, ta-lib is brought up, but during the build it claims it is missing.Crotch
E
5

I downloaded a ZIP project and on building it faced the same issue. This issue was resolved by checking the source of nuget packages- Tools->Nuget Package Manager-> Package Manager Settings-> Nuget Package Manager-> Package Sources

enter image description here

Check the sources of the packages. This might be causing the issue.

Edroi answered 3/3, 2021 at 16:51 Comment(0)
D
2

To solve this error "Unable to find fallback package folder" you need to create an empty folder in that directory as follows: /usr/local/share/dotnet/sdk/NuGetFallbackFolder

Denature answered 25/1, 2022 at 13:47 Comment(0)
S
-1

I found a solution that suited me better: The file c:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.FallbackLocation.config contained the "bad" path. I corrected that, and so solved the problem.

Solipsism answered 14/3, 2023 at 8:36 Comment(0)
Q
-1

create folder NuGetPackages in=>.../Shared

Quartern answered 1/4 at 9:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.