Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core assembly search order

In .NET Framework, the loader searches dependencies in current folder and then in GAC.

  1. But in .NET Core there is no GAC, so does .NET Core assembly loader only search assemblies in current folder or in global nuget cache(someuser/.nuget/packages folder) also?

  2. Also I found a /usr/local/share/dotnet/shared folder in my Mac(C:\Program Files\dotnet\shared in Windows) where all base libraries are located, like System.Runtime.dll, System.Collections.dll.
    Does assembly loader looks there too?

  3. Also I found that these base libraries are duplicated also in in global nuget cache.
    Why?

like image 215
Roman Roman Avatar asked Oct 07 '17 11:10

Roman Roman


1 Answers

The directories used by the PackageCompilationAssemblyResolver will be largely dependent on your environment. However, they may include:

  • C:\Program Files\dotnet\store\x64\netcoreapp2.0 (or equivalent path for your machine)
  • C:\Users\{user}\.nuget\packages
  • C:\Program Files\dotnet\sdk\NuGetFallbackFolder

Note that this is just for packages (i.e NuGet). Other assembly resolvers exist for references and application assemblies...

Note that if you are using an assembly resolver directly in your code, you can specify the paths used for resolution as follows:

ICompilationAssemblyResolver assemblyResolver = new CompositeCompilationAssemblyResolver
                        (new ICompilationAssemblyResolver[]
{
    new AppBaseCompilationAssemblyResolver(basePath),       //e.g. project path
    new ReferenceAssemblyPathResolver(defaultReferenceAssembliesPath, fallbackSearchPaths),
    new PackageCompilationAssemblyResolver(nugetPackageDirectory)   //e.g. C:\Users\\{user}\\.nuget\packages

});

For more details on managing the resolution of assemblies within you code, see this article - Resolving Assemblies in .NET Core

like image 148
SpruceMoose Avatar answered Oct 07 '22 08:10

SpruceMoose