.NET Core程序集搜索顺序 [英] .NET Core assembly search order

查看:229
本文介绍了.NET Core程序集搜索顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.NET Framework中,加载程序先在当前文件夹中搜索依赖关系,然后在GAC中搜索。

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


  1. 但是在.NET Core中没有GAC,.NET Core程序集加载器是否仅在当前文件夹或全局nuget缓存(someuser / .nuget / packages文件夹)中搜索程序集?

  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?

我还在我的Mac(C:\Program Files\dotnetdWindows共享)中找到了一个/ usr / local / share / dotnet / shared文件夹,所有基本库都位于该文件夹中,例如System.Runtime.dll, System.Collections.dll。

程序加载器也在那里吗?

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?

我还发现这些基础库在全局nuget缓存。

为什么?

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


推荐答案

PackageCompilationAssemblyResolver使用的目录在很大程度上取决于您的环境。但是,它们可能包括:

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(或计算机的等效路径)

  • C:\Users\ {user} \.nuget\packages

  • C:\Program文件\dotnet\sdk\NuGetFallbackFolder

请注意,这仅适用于软件包(即NuGet)。存在其他用于引用和应用程序程序集的程序集解析器...

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

});

有关在代码中管理程序集解析的详细信息,请参见本文-在.NET Core中解析程序集

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

这篇关于.NET Core程序集搜索顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆