开发者

.net dll dependencies checking

开发者 https://www.devze.com 2023-01-28 17:38 出处:网络
i have small winforms application, which uses about 20 external dlls. how can i check f开发者_运维问答or all their existance, while application initializing?

i have small winforms application, which uses about 20 external dlls. how can i check f开发者_运维问答or all their existance, while application initializing? to say:"u dont have some dll, install it corrctly".


You have to loop through all custom types (using reflections) used in your application and try to create an instance of each of them. Of course in try/catch. Then have a catch on FileNotFoundException and inform the user there if some libs are missing.

When you create instance of types used in your application AppDomain loads needed libs (so it will throw exception if file is not found).

I think that will help.


If one of the required assemblies are missing your application might not even be loaded by the CLR. So you could write a loader application which will do the job of checking the existence of the required assemblies and if they exist Process.Start the main application.


If you use a plugin-style architecture then you can resolve all your dependencies late -- on demand even -- and you can take control of what happens if a dependency can't be resolved.

It doesn't need to be complicated -- see for example this simple approach.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号