.NET Core assembly search order

筅森魡賤 提交于 2020-01-22 15:17:06

问题


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?


回答1:


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




回答2:


.Net core is based on Nuget packages being cross platform. NET Core applications rely heavily on NuGet to resolve their dependencies, which simplifies development.

You can check link Is there any GAC equivalent for .NET Core?



来源:https://stackoverflow.com/questions/46619499/net-core-assembly-search-order

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!