microsoft / vscode-dotnettools

This is a feedback repository to capture issues logged for the C# Dev Kit and related extensions from Visual Studio Code
Other
233 stars 13 forks source link

[BUG] Unable to find fallback package folder 'C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages' on Linux devcontainer #1138

Open dibarbet opened 5 months ago

dibarbet commented 5 months ago

Describe the Issue

Hitting an issue opening Roslyn.sln inside a linux container from Windows. Using VSCode devcontainers and the devcontainer.json here - https://github.com/dotnet/roslyn/blob/main/.devcontainer/devcontainer.json

There is a fault thrown during project loading

=====================
5/22/2024 12:12:50 AM
LimitedFunctionality
StreamJsonRpc.RemoteInvocationException: Request nominateProject failed with message: Cannot read properties of undefined (reading 'size')
   at StreamJsonRpc.JsonRpc.InvokeCoreAsync[TResult](RequestId id, String targetName, IReadOnlyList`1 arguments, IReadOnlyList`1 positionalArgumentDeclaredTypes, IReadOnlyDictionary`2 namedArgumentDeclaredTypes, CancellationToken cancellationToken, Boolean isParameterObject)
   at Microsoft.VisualStudio.ProjectSystem.PackageReferences.NuGetRestoreService.NominateAsync(ProjectRestoreInfo restoreData, IReadOnlyCollection`1 inputVersions, CancellationToken cancellationToken)
===================

The projects output window shows multiple instances of

2024-05-22 00:13:04.630 [error] (/workspaces/roslyn/src/Features/CSharp/Portable/Microsoft.CodeAnalysis.CSharp.Features.csproj): 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.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)

The Windows nuget package path there is suspicious. I don't believe it is coming from the Roslyn repo configuration, as the repo works fine on a normal linux install (and also in a github codespace using the same devcontainer.json, but I believe using Linux as the host OS instead of Windows).

Steps To Reproduce

  1. Clone the roslyn repo
  2. Open in VSCode, make sure to have the devcontainer extension and docker installed.
  3. Run the 'rebuild and reopen in devcontainer' command image
  4. Wait for a bit for the sln to load, note the project system fault pop-up.

Expected Behavior

No project system fault pop up

Environment Information

dibarbet commented 5 months ago

possibly related to https://github.com/microsoft/vscode-dotnettools/issues/849 (cc @tmeschter )

tmeschter commented 5 months ago

Moving to area-nuget for initial investigate as the ResolvePackageAssets tasks is failing during a design-time build.

kartheekp-ms commented 1 month ago

NuGet.Packaging.Core.PackagingException: Unable to find fallback package folder 'C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages'.

The error is related to a known bug in the NuGet (see https://github.com/NuGet/Home/issues/7012). The issue arises because, when you run a restore operation on a Windows host, certain files (like project.assets.json) will have paths formatted for Windows, which may not work when opening the project in a Linux container, as Linux uses different path formats.

Even if this specific bug is fixed, the restore process would log an error instead of throwing an exception. This means that while exceptions might be avoided, errors could still appear during design-time builds.

@dibarbet - I'm not very experienced with containers, but I think that files listed in .gitignore shouldn't be transferred when opening a project in a container to avoid issues like this. Could you try deleting the artifacts/ folder before opening the repository in the container to see if that fixes the issue?

I deleted the contents of the artifacts/ folder on the Windows host before opening the solution in the container, and I couldn't reproduce the restore error.

I also tried adding a .dockerignore file to exclude the artifacts/ folder and included a script to delete the folder recursively in restore.sh. However, the error still persists, so maybe I'm doing something wrong.

StreamJsonRpc.RemoteInvocationException: Request nominateProject failed with message: Cannot read properties of undefined (reading 'size')

This error is due to https://github.com/microsoft/vscode-dotnettools/issues/636#issuecomment-1792787521.