Unable to find fallback package folder with Windows path on Linux
Describe the bug
The dotnet SDK is unable to run on Linux. A simple project that builds fine on Windows fails to build on Linux with a message like this:
/home/yves/.dotnet/sdk/8.0.303/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:
The "ResolvePackageAssets" task failed unexpectedly.
NuGet.Packaging.Core.PackagingException: Unable to find fallback package folder 'C:\Program Files (x86)\Microsoft
Visual Studio\Shared\NuGetPackages'.
at NuGet.Packaging.FallbackPackagePathResolver..ctor(String userPackageFolder, IEnumerable`1 fallbackPackageFol
ders)
at Microsoft.NET.Build.Tasks.NuGetPackageResolver.CreateResolver(IEnumerable`1 packageFolders)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, B
yte[] settingsHash)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
at Microsoft.NET.Build.Tasks.TaskBase.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggin
gContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
To Reproduce
dotnet publish --tl -c Release -r linux-arm64 --self-contained
I'm not sure what other data to provide here. My solution has several projects and in the past, all of them failed with this error. After an undocumented change, it worked for a while. After more code editing, it now fails with only one of the projects.
I guess something is hard-coded to Windows here and that needs to be removed. Maybe a search for that wrong path in the source code of the SDK helps.
Currently, I am blocked and cannot build my project anymore.
Workarounds have been described to "simply create that directory" (here: "C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages"), but it didn't help here and it's unclear where and how this directory should be created. It's not a "rooted" directory by Linux terms, so where is it looked for, and how would it handle the backslashes which are escape characters in a Linux shell. So that's of no use.
Exceptions (if any)
See description
Further technical details
This is running in Windows 11 WSL "Ubuntu" (22.04). The .NET SDK was installed with the provided install script, not a package manager.
Output of dotnet --info:
.NET SDK:
Version: 8.0.303
Commit: 29ab8e3268
Workload version: 8.0.300-manifests.c915c39d
MSBuild version: 17.10.4+10fbfbf2e
Runtime Environment:
OS Name: ubuntu
OS Version: 22.04
OS Platform: Linux
RID: linux-x64
Base Path: /home/yves/.dotnet/sdk/8.0.303/
.NET workloads installed:
There are no installed workloads to display.
Host:
Version: 8.0.7
Architecture: x64
Commit: 2aade6beb0
.NET SDKs installed:
8.0.303 [/home/yves/.dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.7 [/home/yves/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.7 [/home/yves/.dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
I found the source code for the NuGet.Packaging call, and it is already passed the invalid directory and checks its existence. But I'm unable to locate the source code for the caller "Microsoft.NET.Build.Tasks.NuGetPackageResolver.CreateResolver". Is that even open source?
Thanks for creating this issue! We believe this issue is related to NuGet tooling, which is maintained by the NuGet team. Thus, we closed this one and encourage you to raise this issue in the NuGet repository instead. Don’t forget to check out NuGet’s contributing guide before submitting an issue!
If you believe this issue was closed out of error, please comment to let us know.
Happy Coding!
yeah, that class is in this repo @ygoe.
Turns out, the issue only appeared when I had Visual Studio opened at the same time. It seems like dotnet publish and Visual Studio were competing on the files somehow. I have to close Visual Studio, then I can build the project in the WSL shell. I never knew this issue before when building with dotnet CLI tools on the same host as Visual Studio was running.
If you are still having problems, please reopen/respond/create a new issue. Thank you!
I keep on hitting this issue with latest VS and .NET 10 (https://github.com/adamsitnik/ProcessPlayground/issues/97)
Repro:
- Open VS, modify some source files.
- Open terminal, start WSL and try to run the tests on Linux.
- If it does not repro immediately, try building the source code few times.
Error:
abc@XYZ:/mnt/d/projects/ProcessPlayground$ dotnet test -c Release -f net10.0
Library net10.0 failed with 1 error(s) and 8 warning(s) (1.0s)
/usr/lib/dotnet/sdk/10.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(266,5): error MSB4018:
The "ResolvePackageAssets" task failed unexpectedly.
NuGet.Packaging.Core.PackagingException: Unable to find fallback package folder 'C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages'.
at NuGet.Packaging.FallbackPackagePathResolver..ctor(String userPackageFolder, IEnumerable`1 fallbackPackageFolders)
at Microsoft.NET.Build.Tasks.NuGetPackageResolver.CreateResolver(IEnumerable`1 packageFolders)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader.CreateReaderFromDisk(ResolvePackageAssets task, Byte[] settingsHash)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheReader..ctor(ResolvePackageAssets task)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ReadItemGroups()
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.ExecuteCore()
at Microsoft.NET.Build.Tasks.TaskBase.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(TaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
VS:
Visual Studio 2026
Microsoft Visual Studio Enterprise
Channel: Insiders
Version: Insiders [11312.210]
FWIW I've assigned copilot to workaround it in my repo and it concluded it with:
This occurs because obj/project.assets.json created on Windows contains platform-specific paths that break cross-platform builds.
That's a correct conclusion - we'd need the NuGet team to alter the behavior of assets files to make the output usable on both windows and WSL hosts directly.
This is one reason why our guidance today is to have a separate clone for WSL (or socker volume mounts, etc).
Chopping and changing between project folders and constantly cleaning or having to close VS all the time to switch between builds is not a feasible way forward for this toolset. Definitely a #metoo moment.
Chopping and changing between project folders and constantly cleaning or having to close VS all the time to switch between builds is not a feasible way forward for this toolset. Definitely a #metoo moment.
I was able to workaround it with:
<PropertyGroup>
<RestoreFallbackFolders>clear</RestoreFallbackFolders>
</PropertyGroup>
I've closed VS2026 on Windows and the project has set the correct Linux paths in project.assets.json and built successfully. Before closing the VS the paths have been windows-style all the time.
Interestingly, the issue does not occur with Visual Studio (2022) running while it is in debug mode and the application is running. Only when not debugging, it interferes with the WSL build on the same source files.
The <RestoreFallbackFolders>clear setting didn't help here. When set for the solution's main project, it would still fail to build two other references projects. When set for those two projects as well, WSL build fails earlier with a different error. I'm not going down that rabbit hole; the proposed workaround is none.
But, if the problem lies with some obj directory, should the new "artifacts" layout help? Doesn't that use separate bin and obj directories per platform? I'm using the file setting in all projects that fail in a build (it's random which projects are affected) and it doesn't help. Here's the Directory.Build.props file:
<Project>
<!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
<PropertyGroup>
<UseArtifactsOutput>true</UseArtifactsOutput>
</PropertyGroup>
</Project>
The new artifacts directory is created where configured, and the old bin/obj directories are not recreated. But the problem persists.
I found a solution for me now. The artifacts path was a good start, but you really need to keep the entire artifacts root separated for normal builds and the Linux build. I do it this way:
For all used projects, create a file Directory.Build.props at solution level:
<Project>
<PropertyGroup>
<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>
</PropertyGroup>
</Project>
Also delete any existing bin and obj directories to clean up any leftovers. The compiler might complain about duplicate (auto-generated) assembly attributes if they're still in the project directory.
This will use the solution-level "artifacts" directory for Visual Studio.
Run the Linux build like this:
# Run script in the solution directory
SLNDIR=$(pwd)
# Clean
[[ -e artifacts2 ]] && rm -r artifacts2
# Build
pushd MyAppProject > /dev/null
dotnet publish --tl -c Release -r linux-arm64 --self-contained -p:ArtifactsPath="${SLNDIR}/artifacts2"
popd > /dev/null
# Can delete the artifacts2 directory again after collecting the output files
This will use the fixed absolute path "artifacts2" inside the root solution directory (not inside each referenced project's solution directory) for all projects referenced by the main project (here MyAppProject). That's a separate directory and so we also have separate obj directories and things won't conflict with each other. The Linux build doesn't care about what Visual Studio does with its build directory.
The "artifacts2" name can be configured with variables (also current time), to support multiple concurrent build environments, if needed.
I run into this issue quite a bit as I primarily develop in Visual Studio on windows but do most of my toolchain work (git, grep, local automation in bash, etc.) on a Ubuntu 24 WSL2 guest. Usually I don't issue dotnet commands in WSL unless I'm doing cross project testing, which I've been doing... quite... a bit lately. Wanted to chime in with some accumulated findings on my own and track any progress on this when it comes.
Root cause found (WSL2 + DrvFS-mounted project path)
Ran into this exact symptom on WSL2 (Ubuntu 24.04) with the .NET SDK's native Linux build (/usr/lib/dotnet, not dotnet.exe via interop) building a project whose source lives on a /mnt/c/... DrvFS mount of the Windows host's C: drive. Dug into the generated restore artifacts under obj/ rather than just retrying, and found what looks like the actual mechanism.
Environment
dotnet --info: SDK 10.0.110, RIDubuntu.24.04-x64NuGetToolVersionin the generated props:7.0.0- Project physically located under
/mnt/c/Users/<user>/...(a WSL2 DrvFS mount of the WindowsC:\Users\<user>\...path) dotnet nuget config pathsconsistently reports a single, correctly-Linux-scopedNuGet.Config(~/.nuget/NuGet/NuGet.Config), with<fallbackPackageFolders><clear /></fallbackPackageFolders>explicitly set and a LinuxglobalPackagesFolder. This is not a case of a stray Windows-styleNuGet.Configbeing picked up — verified directly, repeatedly, across every failing run.
Symptom
error MSB4018: The "ResolvePackageAssets" task failed unexpectedly.
error MSB4018: NuGet.Packaging.Core.PackagingException: Unable to find fallback package folder 'C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages'.
at NuGet.Packaging.FallbackPackagePathResolver..ctor(String userPackageFolder, IEnumerable`1 fallbackPackageFolders)
at Microsoft.NET.Build.Tasks.NuGetPackageResolver.CreateResolver(IEnumerable`1 packageFolders)
at Microsoft.NET.Build.Tasks.ResolvePackageAssets.CacheWriter..ctor(ResolvePackageAssets task)
...
What's actually happening
The corruption isn't in NuGet.Config or in project.assets.json's own packageFolders section (both of those are frequently clean even on a failing build). It's in obj/<project>.csproj.nuget.dgspec.json — the restore dependency-graph spec MSBuild passes forward. On a bad restore, that file's projects dictionary keys are written as Windows-style paths (C:\Users\<user>\projects\...\Foo.csproj) even though the project was restored via its /mnt/c/... Linux path using the native Linux dotnet CLI. Once a project's key is in that Windows form, its restore.fallbackFolders entry gets C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages injected — the well-known "restore offline via VS's bundled package cache" default — completely independent of anything in NuGet.Config. That folder is a real path (Visual Studio is installed on the Windows side and it's visible to WSL2 through the same DrvFS mount), but the Linux-native SDK obviously can't resolve it as a filesystem path, hence the PackagingException at build time in ResolvePackageAssets, which reads its package-folder list from this graph spec / the paired .nuget.g.props rather than re-deriving it from NuGet.Config at build time.
Confirmed by direct patch test: hand-stripping the Windows-style paths and the VS fallback-folder entry from all four generated artifacts (.nuget.dgspec.json, .nuget.g.props, .nuget.g.targets, project.assets.json) for every project in the restore graph made the MSB4018 disappear completely — replaced by an unrelated NETSDK1064 (missing package) caused by the hand-edit itself desyncing the lock file, not by the fallback-folder logic. That strongly suggests the fallback-folder injection is driven by the Windows-style path shape of the project key in the graph spec, not by platform detection via RuntimeInformation/OSPlatform directly (since the actual runtime is unambiguously Linux throughout).
Non-deterministic, not simple staleness: with obj/ fully deleted and the MSBuild build-server processes killed (dotnet build-server shutdown) before each attempt, running the identical dotnet restore command back-to-back produced a clean (Linux-only) graph spec on some runs and a Windows-path-contaminated one on others — no code or config changes in between. So this isn't purely "a stale cached artifact from an earlier Windows-side restore" — something in path/settings resolution during restore itself is intermittently deciding the project is Windows-hosted, seemingly influenced by the fact that the DrvFS-mounted path is also a valid, resolvable Windows path from the same machine's perspective.
Multi-project detail, in case it's relevant to reproducing: in a graph with a local ProjectReference into a sibling repo (also under /mnt/c/...), that sibling project's own obj/ independently carries the same contamination, and has to be clean too — cleaning only the entry project's obj/ isn't sufficient to reproduce a passing build, which cost some time to notice.
Why this probably doesn't reproduce for most people
This is specific to running the Linux-native .NET SDK against source that lives on a DrvFS mount of the Windows filesystem (/mnt/c/... from WSL2) — a fairly specific but not rare setup (anyone keeping WSL2 and Visual Studio on Windows in sync against the same working tree via the /mnt/c mount would hit it). It would not reproduce for source living on WSL2's native filesystem, nor for dotnet.exe running natively on Windows against the same path in its native C:\... form.
Happy to provide a minimal repro solution and/or a binlog (-bl) of a failing restore if that would help narrow down where in the graph-spec-writing code path the Windows-path-shaped key gets treated as "this project is on Windows" for fallback-folder purposes.
This isn't a blocker for me, but a huge annoyance as a fallback directive seems to be what's failing the whole process. Would love to see some progress on this as it's one of the few areas in the dotnet ecosystem that seems to be confused working between OS's.