Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation path differs from install path when using PackagePathResolver in .NET 8 #13100

Closed
koma-tompit opened this issue Dec 20, 2023 · 1 comment
Assignees
Labels
Functionality:SDK The NuGet client packages published to nuget.org Type:Bug

Comments

@koma-tompit
Copy link

koma-tompit commented Dec 20, 2023

NuGet Product Used

NuGet SDK

Product Version

NuGet.Packaging: 6.8.0.131, Dotnet info: Host: Version: 8.0.0 Architecture: x64 Commit: 5535e31a71 RID: linux-x64 .NET SDKs installed: No SDKs were found. .NET runtimes installed: Microsoft.AspNetCore.App 8.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 8.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Worked before?

Works fine with .NET 7.0.14

Impact

I'm unable to use this version

Repro Steps & Context

Relevant code:

var packageExtractionContext = new PackageExtractionContext(PackageSaveMode.Defaultv3, XmlDocFileSaveMode.None, null, Logger);
var frameworkReducer = new FrameworkReducer();
var result = new PackageDescriptor();
IEnumerable<SourcePackageDependencyInfo> packages = new List<SourcePackageDependencyInfo>(); //Is actually a function parameter, filled with dependencies
var RootPath = "/home/user/packages/";

foreach (var installer in packages)
{
  PackageReaderBase packageReader;

  var installedPath = PathResolver.GetInstalledPath(installer);
  
  if (string.IsNullOrEmpty(installedPath)) //In this case, always returns null, as packages are not installed
  {
    var downloadResource = await installer.Source.GetResourceAsync<DownloadResource>(CancellationToken.None);
    var downloadResult = await downloadResource.GetDownloadResourceResultAsync(installer, new PackageDownloadContext(CacheContext), RootDirectory, Logger, CancellationToken.None);
  
    packageReader = downloadResult.PackageReader;
  }
  else
    packageReader = new PackageFolderReader(installedPath);
  
  //PathResolver.GetInstallPath(installer) returns a path I cannot access at the moment, for example /home/user/packages/Newtonsoft.Json/3.0.5/
  //The actual path on the drive is /home/user/packages/newtonsoft.json/3.0.5/
  var folder = Path.Combine(PathResolver.GetInstallPath(installer), installer.Version.ToString());
  //The code then proceeds to extract dlls by using the folder and some other parameters. As the folder is invalid, the application crashes
}

I made a workaround for this in our resolver, where I replace the package id in the path with a lowercase version, which temporarily resolved the issue when using packages to compile c# scripts in runtime.

The problem is the Razor view resolver, which is out of reach of modification and complains of the same error:

Cannot find compilation library location for package 'System.Security.Cryptography.Pkcs' at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List`1 assemblies) at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths() ...

This happens when compiling a razor view at runtime which is dependant on a NuGet package.

What I find strange is that this appears to work under Windows and a WSL2 Debian installation, and in docker using mcr.microsoft.com/dotnet/aspnetcore:7.0, but consistently crashes in docker, using the mcr.microsoft.com/dotnet/aspnetcore:8.0 image. The only difference there being the project sdk versions, so one built with .NET 7 and the latter, crashing one, with .NET 8.

Verbose Logs

No response

@nkolev92
Copy link
Member

nkolev92 commented Jan 22, 2024

Can you try using VersionFolderPathResolver?

VersionFolderPathResolver is what's used for the global packages folder.

@nkolev92 nkolev92 self-assigned this Jan 22, 2024
@NuGet NuGet locked and limited conversation to collaborators Jan 22, 2024
@nkolev92 nkolev92 converted this issue into discussion #13178 Jan 22, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Functionality:SDK The NuGet client packages published to nuget.org Type:Bug
Projects
None yet
Development

No branches or pull requests

4 participants