3

Is it possible to embed an exe file in a class library (dll file)?

I want to use this exe without the necessity of copying it manually to my workstation. In other words, if I want to use my C# class library in another app, I won't need to copy these exe files in a folder and pass the path of this folder in my app.

If there is a way how to do this, it would be great.


sorry but what I mean is just, I made a library for screenshots using Selenium Webdriver and when creating a new webdriver object, I need to pass the exe file of the webdriver. what I need the most is that I don't want to copy the exe file if I will use this library to another workstation for example, I want everything to be packaged as one file Thank you

1
  • If this EXE a .NET app you made yourself and have the code for?
    – Crono
    Commented Apr 4, 2014 at 14:35

2 Answers 2

2

Well, technically you can embed a binary file as a resource within a DLL (by adding the file as a binary resource through the project properties), but you'll still need to save the file to disk in order to execute it (which is assume what you're trying to do) and will possibly have security issues unless your application is fully trusted.

If the binary file is a resource you can extract the bytes from the static Properties class:

byte[] exe = Properties.Resources.MyExe;

and save it to disk like any other byte array.

2
  • Of course, you must have the right to copy it to disk, and the permissions to execute it once it has been copied. Commented Apr 4, 2014 at 17:23
  • sorry but what I mean is just, I made a library for screenshots using Selenium Webdriver and when creating a new webdriver object, I need to pass the exe file of the webdriver. what I need the most is that I don't want to copy the exe file if I will use this library in another workstation or another project for example, I want everything to be packaged in one file
    – nabil
    Commented Apr 8, 2014 at 8:48
-1

If you own the code for the EXE then it would be a lot better for you to turn your EXE code into a library. Then you'll be able to refer to that library from anywhere and call any public functionnality it has. It's a far, far, FAR better approach.

Should you still need to run that code as a standalone process, nothing prevents you from making a new EXE front that will refer to that same library.

Now if you do not have the code, then depending on your deployment strategy you may prefer creating a reusable deployment component / module that can be attached to other application setups.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.