了解DLL的地狱

扫码查看
本文介绍了了解DLL的地狱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解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的允许位置是什么?

解决方案

您可以使用以下代码确定所有加载的程序集,并检查他们:

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

Console.WriteLine(这是这个appdomain\\\
中加载的程序集)
foreach(assembly a in loadedAssemblies)
{
Console.WriteLine(a.FullName);
}

从帖子()



这里是运行时如何查找程序集 p>


I have trouble understanding the mechanisms by which Visual Studio resolves dependencies to .NET dlls. In some .csproj file, I have some dependency as follows.

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

However, the HintPath pointed to an invalid path, yet Visual Studio was able to build and deploy the project as desired, apparently taking the dll from somewhere else. In my case, this wasn't a major problem as the final result was as desired, but I ultimately do not understand by which mechanism dependencies to .NET dlls are resolved.

How can I find out which dll is actually referenced when building a Visual Studio project? What are the permitted locations for dlls?

解决方案

You can use the following code to determine all loaded assemblies and also check the path of them:

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);
}

from the post (Determine Loaded Assemblies)

And here is the documentation of "How the Runtime Locates Assemblies"

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

这篇关于了解DLL的地狱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 01:41
查看更多