【问题标题】:Understanding DLL hell了解 DLL 地狱
【发布时间】:2016-06-24 09:00:13
【问题描述】:

我无法理解 Visual Studio 将依赖关系解析为 .NET dll 的机制。在一些.csproj 文件中,我有一些依赖如下。

<Reference Include="SomeDependency,
                    Version=SomeVersion,
                    Culture=neutral,
                    PublicKeyToken=SomePublicKeyToken,
                    processorArchitecture=MSIL">
    <SpecificVersion>False</SpecificVersion>
    <HintPath>SomeHintPath</HintPath>
</Reference>

然而,HintPath 指向了一个无效的路径,但 Visual Studio 能够根据需要构建和部署项目,显然是从其他地方获取 dll。就我而言,这不是主要问题,因为最终结果符合预期,但我最终不明白通过哪种机制解决对 .NET dll 的依赖关系。

在构建 Visual Studio 项目时,如何找出实际引用了哪个 dll? dll 允许的位置是什么?

【问题讨论】:

  • 这能回答你的问题吗:(stackoverflow.com/questions/49972/…)
  • @KevinWallis 是的,有点,感谢您的参考。然而,转念一想,事实并非如此;基本上答案是“视情况而定”。

标签: c# .net visual-studio dll


【解决方案1】:

您可以使用以下代码来确定所有加载的程序集并检查它们的路径:

AppDomain ad = AppDomain.CurrentDomain;
Assembly[] loadedAssemblies = ad.GetAssemblies();

Console.WriteLine("Here are the assemblies loaded in this appdomain\n");
foreach (Assembly a in loadedAssemblies)
{
    Console.WriteLine(a.FullName);
}

来自帖子 (Determine Loaded Assemblies)

这里是“运行时如何定位程序集”的文档

https://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.110).aspx

【讨论】:

  • 被接受为明确的答案,因为显然该链接是最全面的来源;但是我希望事情不会那么复杂。
  • @Codor 是的,它很安静
猜你喜欢
  • 1970-01-01
  • 2016-05-29
  • 1970-01-01
  • 2015-08-30
  • 2017-11-21
  • 1970-01-01
  • 2011-01-22
  • 2019-01-21
  • 1970-01-01
相关资源
最近更新 更多