Jump to content

[C#] External Third Party Libraries

MatazaNZ

Hi all, I was wondering if someone could give me some insight into this. I've done some searches into this topic, but I haven't found much that I'm able to either understand, or I'm not at that level yet. 

 

Basically, I don't know how to include third party .dll libraries with my finished application without distributing the library with my .exe. I'm creating a WPF application, and I'm using the WPF Extended Toolkit for the controls it includes, and while my program compiles and runs just fine under debug, as the toolkit dll file is in the bin/debug folder, when I compile for release, the dll isn't in the bin/release folder, so it will not run. I know I can get around that by simply keeping the .dll with the .exe file, but that becomes an issue when I want to distribute it to friends and family, as they don't know to keep the files together.

 

My main question is where would I need to put the .dll file for deployment? Will it be included if I set up my project to install with an installer package? Some people have said to keep it in a top level folder, parallel to the solution, but that hasn't given me much headway, and I don't know the context. Any help would be greatly appreciated 

Link to comment
Share on other sites

Link to post
Share on other sites

So this will apply in general and not just to C#.  When you are making use of a third party dll, it must be included with the executable...the exception would be for dlls that get installed with other programs, and are accessible system wide (but in this is a smaller case and likely doesn't apply here).

 

Essentially there are a few options.  If the third party dll is written in C#, you *might* be able to get the .lib type of file so when you compile you actually compile the code into the exe (Uhm to be honest, I am not sure this is possible in C# though, I have never tried it...but I am use to using C++ at the moment and have done it with that).

 

Another option would be what you mentioned, an installer that installs the dll along side the exe.

 

Another option, would be to dynamically load the dll, and make the program check for the dll.  If the dll isn't found then it downloads the dll (or not something I recommend, but have the program contain the dll embedded in it and instead of downloading it, you just copy the dll out of the binary data).

 

That is all I can think of, I am sure there are other people who will be able to help you out more though.

0b10111010 10101101 11110000 00001101

Link to comment
Share on other sites

Link to post
Share on other sites

If you just want to distribute to friends/family then you should simply package everything in a simple installer. ClickOnce is one easy option and the install location isn't made known to the person installing it so it's hard to find and mess with for someone not computer savvy.

 

The Embedding DLLs in a compiled executable question on stack overflow may also be helpful to you if that's the route you want to go.

 

The How to compile all files to one exe? question on stack overflow may help as well. (edit: actually after reading it again, probably not helpful as it's about resources not dlls but I'll leave it here anyway lol)

Link to comment
Share on other sites

Link to post
Share on other sites

So this will apply in general and not just to C#.  When you are making use of a third party dll, it must be included with the executable...the exception would be for dlls that get installed with other programs, and are accessible system wide (but in this is a smaller case and likely doesn't apply here).

 

Essentially there are a few options.  If the third party dll is written in C#, you *might* be able to get the .lib type of file so when you compile you actually compile the code into the exe (Uhm to be honest, I am not sure this is possible in C# though, I have never tried it...but I am use to using C++ at the moment and have done it with that).

 

Another option would be what you mentioned, an installer that installs the dll along side the exe.

 

Another option, would be to dynamically load the dll, and make the program check for the dll.  If the dll isn't found then it downloads the dll (or not something I recommend, but have the program contain the dll embedded in it and instead of downloading it, you just copy the dll out of the binary data).

 

That is all I can think of, I am sure there are other people who will be able to help you out more though.

 

 

If you just want to distribute to friends/family then you should simply package everything in a simple installer. ClickOnce is one easy option and the install location isn't made known to the person installing it so it's hard to find and mess with for someone not computer savvy.

 

The Embedding DLLs in a compiled executable question on stack overflow may also be helpful to you if that's the route you want to go.

 

The How to compile all files to one exe? question on stack overflow may help as well. (edit: actually after reading it again, probably not helpful as it's about resources not dlls but I'll leave it here anyway lol)

 Thank you both for your answers :D I'll definitely take a look into the ClickOnce installers, but I would like for the install location to be changed if the user wants it to, so one of the other installer options might also be worth a look. What I think I'll do is build a test program for my friend, using the .dll, and see if I can get the installers to work as intended, and see how that goes.

Link to comment
Share on other sites

Link to post
Share on other sites

ClickOnce is a great way of distributing small applications if you have a website where you can host them. One thing to keep in mind is if you are using a Self Signed Coding certificate the users that installs the application will have to confirm it. And in windows 8 they made quite anoying to do so.

If its only .net dlls you can use a merger to merge the dlls with the exe, if you have none .net libs you need embed them as resources and create your own lib loader for them like the links madknight3 posted.

Link to comment
Share on other sites

Link to post
Share on other sites

You might also like to look at WIX. Another thing to keep in mind is that you can always check for binding failures with Fuslogvw.exe.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

ClickOnce is a great way of distributing small applications if you have a website where you can host them. One thing to keep in mind is if you are using a Self Signed Coding certificate the users that installs the application will have to confirm it. And in windows 8 they made quite anoying to do so.

If its only .net dlls you can use a merger to merge the dlls with the exe, if you have none .net libs you need embed them as resources and create your own lib loader for them like the links madknight3 posted.

How would I go about a Coding certificate? I've heard that using them can also help prevent issues with antivirus programs, as the program doesn't have many users

Link to comment
Share on other sites

Link to post
Share on other sites

How would I go about a Coding certificate? I've heard that using them can also help prevent issues with antivirus programs, as the program doesn't have many users

 

The free versions:

  1. You use the automatic self signed coding certificate visual studio creates for you that will require the users to confirm that they should run/install the program.
  2. You create a root certificate and use that to sign your own coding certificate and use that to sign the click once installer. That way the users only need to install your root certificate once and the program will show up as signed.

The other way is that you buy a coding certificate from some valid certificate vendor like https://www.digicert.com/ (223usd) or https://startssl.com/ (59usd)

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×