.NET Core程序集搜索顺序

编程入门 行业动态 更新时间:2024-10-27 15:18:05
本文介绍了.NET Core程序集搜索顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

  • 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程序集搜索顺序

    本文发布于:2023-11-14 13:21:15,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1587321.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:顺序   程序   NET   Core

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!