How to check for DLL dependency?

2019-01-01 10:39发布

Sometimes when I'm doing a little project I'm not careful enough and accidently add a dependency for a DLL that I am not aware of. When I ship this program to a friend or other people "it doesn't work" because "some DLL" is missing. This is ofcourse because the program can find the DLL on my system, but not on theirs.

Is there a program/script that can scan an executable for DLL dependencies or execute the program in a "clean" DLL-free environment for testing to prevent these oops situations?

11条回答
妖精总统
2楼-- · 2019-01-01 11:02
琉璃瓶的回忆
3楼-- · 2019-01-01 11:02

NDepend was already mentioned by Jesse (if you analyze .NET code) but lets explain exactly how it can help.

Is there a program/script that can scan an executable for DLL dependencies or execute the program in a "clean" DLL-free environment for testing to prevent these oops situations?

In the NDepend Project Properties panel, you can define what are application assemblies to analyze (in green) and NDepend will infer Third-Party assemblies used by application ones (in blue). A list of directories where to search application and third-party assemblies is provided.

NDepend Project Properties Application and Third-Party assemblies

If a third-party assembly is not found in these directories, it will be in error mode. For example if I remove the .NET Fx directory C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319 I can see that .NET Fx third-party assemblies are not resolved:

NDepend Project Properties Application and Third-Party assemblies not resolved

Disclaimer: I work for NDepend

查看更多
闭嘴吧你
4楼-- · 2019-01-01 11:05
  1. There is a program called "Depends"
  2. If you have cygwin installed, nothing simpler then ldd file.exe
查看更多
余生无你
5楼-- · 2019-01-01 11:09

I can recommend interesting solution for Linux fans. After I explored this solution, I've switched from DependencyWalker to this.

You can use your favorite ldd over Windows-related exe, dll.

To do this you need to install Cygwin (basic installation, without no additional packages required) on your Windows and then just start Cygwin Terminal. Now you can run your favorite Linux commands, including:

$ ldd your_dll_file.dll

UPD: You can use ldd also through git bash terminal on Windows. No need to install cygwin in case if you have git already installed.

查看更多
泛滥B
6楼-- · 2019-01-01 11:09

The safest thing is have some clean virtual machine, on which you can test your program. On every version you'd like to test, restore the VM to its initial clean value. Then install your program using its setup, and see if it works.

Dll problems have different faces. If you use Visual Studio and dynamically link to the CRT, you have to distribute the CRT DLLs. Update your VS, and you have to distribute another version of the CRT. Just checking dependencies is not enough, as you might miss those. Doing a full install on a clean machine is the only safe solution, IMO.

If you don't want to setup a full-blown test environment and have Windows 7, you can use XP-Mode as the initial clean machine, and XP-More to duplicate the VM.

查看更多
情到深处是孤独
7楼-- · 2019-01-01 11:11

On your development machine, you can execute the program and run Sysinternals Process Explorer. In the lower pane, it will show you the loaded DLLs and the current paths to them which is handy for a number of reasons. If you are executing off your deployment package, it would reveal which DLLs are referenced in the wrong path (i.e. weren't packaged correctly).

Currently, our company uses Visual Studio Installer projects to walk the dependency tree and output as loose files the program. In VS2013, this is now an extension: https://visualstudiogallery.msdn.microsoft.com/9abe329c-9bba-44a1-be59-0fbf6151054d. We then package these loose files in a more comprehensive installer but at least that setup project all the dot net dependencies and drops them into the one spot and warns you when things are missing.

查看更多
登录 后发表回答