查找依赖项/dll源头

3

为了安全起见,我需要更新Microsoft.Data.OData dll/package。不幸的是,我们不清楚为什么这个dll在我们的输出(bin文件夹)中。它是间接使用的,我们想知道它来自哪里。

这个包没有在csproj文件中引用 - 我们正在使用旧版csproj的<PackageReference>。(<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

有办法找出这个dll(Microsoft.Data.OData.dll)来自哪里吗?我尝试过:

  • Searched in the code - it's not used by our code.

  • Checked the build log. I see this in the build log:

      Primary reference "Microsoft.Data.OData, Version=5.8.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35".
      2>      Resolved file path is "C:\Users\MyUsername\.nuget\packages\microsoft.data.odata\5.8.2\lib\net40\Microsoft.Data.OData.dll".
      2>      Reference found at search path location "{RawFileName}".
      2>      Found related file "C:\Users\MyUsername\.nuget\packages\microsoft.data.odata\5.8.2\lib\net40\Microsoft.Data.OData.xml".
      2>      Found satellite file "de\Microsoft.Data.OData.resources.dll".
      2>      Found satellite file "es\Microsoft.Data.OData.resources.dll".
      2>      Found satellite file "fr\Microsoft.Data.OData.resources.dll".
      2>      Found satellite file "it\Microsoft.Data.OData.resources.dll".
      2>      Found satellite file "ja\Microsoft.Data.OData.resources.dll".
      2>      Found satellite file "ko\Microsoft.Data.OData.resources.dll".
      2>      Found satellite file "ru\Microsoft.Data.OData.resources.dll".
      2>      Found satellite file "zh-Hans\Microsoft.Data.OData.resources.dll".
      2>      Found satellite file "zh-Hant\Microsoft.Data.OData.resources.dll".
      2>      This reference is not "CopyLocal" because at least one source item had "Private" set to "false" and no source items had "Private" set to "true".
      2>      The ImageRuntimeVersion for this reference is "v4.0.30319".
    
  • Checked the csproj (no packages.config here) - it's not there

  • Cleaned the bin folder and rebuild - it clear which project this dll is outputing, and it's there after rebuild.

是否有其他日志或工具可供使用?


穷人的方法:从输出目录中删除DLL,运行应用程序,看哪个类报错。 - Ian Kemp
1个回答

4
您可以通过向任何MSBuild执行传递-bl开关来创建二进制MSBuild日志。例如,msbuild -bl运行默认目标(通常是构建),msbuild -t:publish -bl在运行发布时获取binlog。
如果您没有指定二进制日志文件名,则默认为当前目录中的msbuild.binlog,而不是项目目录。
然后,您可以使用https://www.msbuildlog.com查看二进制日志。您可以搜索dll文件名,并找到它被复制的位置(以及构建中的每个其他引用)。
我使用了一个SDK样式的项目进行测试,因为这样更加容易和快捷,但对于非SDK样式的项目也是类似的。dll文件将被复制到名为_CopyFilesMarkedCopyLocal的目标文件夹中,任务名为Copy。我以NuGet.Versioning包作为示例,并看到以下信息:

从"C:\Users\zivkan\.nuget\packages\nuget.versioning\5.7.0\lib\netstandard2.0\NuGet.Versioning.dll"复制文件到"C:\src\test\binlogDemo\bin\Debug\net5.0\NuGet.Versioning.dll"。

请注意,如果您使用诊断详细信息构建,则几乎所有信息都会出现在文本日志输出中。因此,这些“从...复制文件到...”的消息并不要求使用binlog,但一旦您习惯了它们,binlog就更容易阅读和使用。

听起来不错!有没有https://www.msbuildlog.com/的替代方案?由于安全策略的限制,我不能将内部信息粘贴到网络上。 - Julian
这也是一个可以安装在本地计算机上的应用程序。我就是这样使用它的,因为它会与 .binlog 扩展名关联起来,所以我可以在命令行上输入 start msbuild.binlog 来快速打开文件。该网站的首页有一个 "下载..." 链接,实际上是一个附加到 GitHub 发布版本的文件。 - zivkan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接