Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out where a dependency / dll came from

For security measures, I need to update the Microsoft.Data.OData dll/package. Unfortunately it's unclear why this dll is in our output (bin folder). It's somewhere indirectly used, and we like to know where.

This package isn't referenced in the csproj file - we are using <PackageReference> with the old-style csproj for this. (<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">)

Is there a way to find out where this dll (Microsoft.Data.OData.dll) comes from? I tried:

  • 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.

Is there some other log or tool which I could use?

like image 234
Julian Avatar asked Oct 22 '25 14:10

Julian


1 Answers

You can create a binary MSBuild log, by passing the -bl switch to any MSBuild execution. For example msbuild -bl to run the default target (usually build), msbuild -t:publish -bl to get a binlog when running a publish.

If you don't specify a binary log file name, it defaults to msbuild.binlog in the current directory, not the project directory.

You can then use https://www.msbuildlog.com to view the binary log. You can search for the dll file name, and find where it's being copied (and every other reference in the build).

I tested with an SDK style project because it's so much easier and quicker, but it will be similar for non-SDK style projects. The dlls are copied to the bin folder in a target called _CopyFilesMarkedCopyLocal, with a task named Copy. I used the NuGet.Versioning package as an example, and I see the message:

Copying file from "C:\Users\zivkan\.nuget\packages\nuget.versioning\5.7.0\lib\netstandard2.0\NuGet.Versioning.dll" to "C:\src\test\binlogDemo\bin\Debug\net5.0\NuGet.Versioning.dll".

Note, if you build with diagnostic verbosity, almost all the information will be present in the text log output. So, these "copying file from ... to ..." messages do not demand the usage of binlogs, but binlogs are so much easier to read and use, once you get used to them.

like image 149
zivkan Avatar answered Oct 25 '25 04:10

zivkan