Click here to Skip to main content
15,031,495 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I wonder if we can build a single EXE file only without any library files going with it such as dll files?
When building a huge and complex application, that's useful and necessary. But my application is small enough to build as a single EXE file only, I have used my own library (its size is about 13KB) to write my application, at first I thought when building, the compiler will include that library in my application but it doesn't. Could you please tell me how I can include it in my application when building? I don't want to rewrite code (plus, it concerns my controls I have used in my app, it's exactly my custom TextBox)
Thank you so much!
Albert Holguin 18-Apr-11 19:47pm
do you have the source for both the exe and the dll that you want to combine?
Philippe Mori 29-May-15 21:30pm
What is the problem with putting all files in the same project? By the way, you can still drag-and-drop controls from the toolbox even if the control is is the application project (just compile the application once so the control appears in the toolbox).

You need ILMerge. Note that this is possible only if the dll's are managed dll's.

Check out the following CodeProject article that explains this:

Merging .NET assemblies using ILMerge[^]


A DLL could either be a .net based dll (managed dll - one with CLR header) or a standard DLL (an example is mscorlib.dll, kernel32.dll,user32.dll etc). Following is a link to SO, that discusses about CLR based dll's[^]

As Pete O'Hanlon said, you may also include all of the source files(or the required ones alone) in your class library to your project so that you don't need an additional DLL.

Hope this helps!
[no name] 18-Apr-11 17:51pm
Thank you for the helpful utility!
Maybe I should use it! However, I still want to find another way them! I don't understand why VS IDEs don't support that work. Is there any difference between .NET dll and my dll, all is written in C#, my one inherits the TextBox class of .NET library.
Thank you!
Karthik. A 18-Apr-11 19:19pm
You are welcome. A .Net DLL is one that has a CLR header. I have updated the question with a link and some explanation. You are saying that you wrote your dll in C#, so it should be a managed (.net) dll. So this certainly is an option for you!
ILMerge is an interesting tool, my 5 for the Solution.
(I'm however not so sure about its usefulness; what's so wrong with multiple libraries?)

At to OP's original question, I feel his deep confusion, but I'm still trying to understand what seems to be a problem. To me, it looks like an artificial problem not existing as such.
Karthik. A 19-Apr-11 0:34am
@SAKryukov - I found it to be useful in a couple of projects I worked, as it involved deploying my application to multiple machines and they didn't want to deploy/manage multiple files.

And regarding the OP, yes I guess so too. That's why I added the edit. He would be better off adding it to the same project too. And thanks for the 5!
Karthik. A 19-Apr-11 0:42am
I missed something, yes, multiple libraries should also be fine and thats one of the important selling points nowadays - code sharing! ILMerge is also helpful like in the case I said in my earlier comment...
[no name] 19-Apr-11 2:32am
Why do I need a single EXE file? It's too simple!
1. Easy to deploy and publish!
2. Without any fears of losing my dll file.
3. If using multiple library application, I should pack them into a single Setup file only for 2 assemblies (my exe and dll)? Is it necessary?
4. I think we need to divide a program into multiple libraries and linking them when NEEDED (this can help save RAM) or the dll files are too large in size or we may need to update our program to next version through these libraries. But my program has only two assemblies, the dll file is too small in size (13KB) and it is very important to help the exe run all the time once the program runs, so there is no Dynamical load here (except the moment when starting loading the program).
5. Multiple libraries are needed when we buy these from a third party developers.
I can see it clearly with more advantages than using multiple libraries!
Thank you so much!
Espen Harlinn 19-Apr-11 16:15pm
Good idea, my 5
If all you're worried about is including the functionality inside your application, then you could simply add the code files into your project as linked code. It's easy enough to do this, by choosing Add existing item from the project, and choose Insert as Link from the Insert button dropdown. By doing this, you can add the actual source files into your project.
[no name] 18-Apr-11 17:32pm
I did the followings:
Right click on my project in the solution explorer, next to Add, Existing Item, select dll file, click on dropdown arrow at right of Add button, and click Add as link. That's all, after that I don't know how to use it in my project, Plus my library is a class of my custom Textbox, and I want to drag and drop instances of it onto my form. How can I do that with a link to my library?
Thank you so much!
Pete O'Hanlon 18-Apr-11 17:38pm
Sorry, but you misunderstood me. I'm talking about adding the code files into your project, using this technique (adding the code files in as linked files). When your code builds, the source is added in to the codebase directly - and is not an external file. I was assuming in my answer here that you didn't want any external dependencies, and that you know how to add references in otherwise.
[no name] 18-Apr-11 18:03pm
I don't think so! I did exactly as what you had told me! I have already added my dll to my project as a Link but I don't know how to use it, so I need your guide more! Could you please make it more detailed about How to use it after added as link ( I have already added it in to my project)!
Thank you so much!
@King Boy: You misunderstood again and again.
1) you need to add ***source*** files.
2) you need to avoid adding them twice (one for library, another time as for embedded into a single exe), so Pete advised to use the as link -- ***not a library link*** -- link as the optional way to add a source file, in VS this is and option in dialog box.

Right, Pete?
(Frankly, you did not express it clearly, no wonder OP got confused.)
Pete O'Hanlon 19-Apr-11 5:16am
That's true. Reading it again, my explanation was less than crystalline, but the concept still stands.
Sergey Alexandrovich Kryukov 19-Apr-11 12:49pm
After it's clear I voted 5. It looks like your Solution was down-voted, maybe due to misunderstanding.
[no name] 19-Apr-11 2:09am
Thank you SA for the clear explanation! But even when I do like that, how can I "DRAG" and "DROP" my custom text box onto my form? I can only create an instance of it by using code, but where is its position on my form? I have also to use code (use Location property), but is it exactly a position I want? It is too difficult to do! Plus I have about 200 such instances of my custom textbox and I think dragging and dropping them onto my forn at design time is the easiest and the most feasible way, no other way to do that.
Could you please give me more suggestions to solve my problem?
Thank you so much!
Sergey Alexandrovich Kryukov 19-Apr-11 12:53pm
This is a different story, a matter of whole article maybe.
You drag-and-drop looks like certain (very usual) abuse of Designer. Avoid absolute positioning (better say, never allow yourself to use it). Always use dock, padding and/or margin.
This deserves a separate answer...
Sergey Alexandrovich Kryukov 19-Apr-11 13:02pm
If posted a separate Solution on the topic.
Philippe Mori 29-May-15 21:20pm
You don't need any DLL to do drag & drop from the toolbox. You can add your custom control to your application if you want. However, you need to build your application for the control to become available in the toolbox.

Alternatively, you might want to consider shared projects if you are using VS 2013 or 2015.
[Answering a follow-up Question]

Thank you SA for the clear explanation! But even when I do like that, how can I "DRAG" and "DROP" my custom text box onto my form? I can only create an instance of it by using code, but where is its position on my form? I have also to use code (use Location property), but is it exactly a position I want? It is too difficult to do! Plus I have about 200 such instances of my custom TextBox and I think dragging and dropping them onto my form at design time is the easiest and the most feasible way, no other way to do that. Could you please give me more suggestions to solve my problem? Thank you so much!
No, it only the easiest way to demonstrate how cool the Designer is. :-) For a serious application such style only slows you down; and the final result may never be achieved. You need to design UI more thoroughly.

Please try to use the list of my (incomplete) directions for better UI design:
GUI Apperance - C#.Net[^],
Zom Out malfunctions when Screen resolution changes[^],
Code behind class implementation[^].

One important aspect here: never use absolute positioning. Always use Dock in combination with Padding and/or Margins. Do not assume fixed sizes of anything. Do not create multiple controls in one container. If there are too many, they belong to a UserControl or a different view. Hide controls which are not currently used — the user also does not want to see too many. This aspect is explain in one of my Solutions referenced above.

Philippe Mori 29-May-15 21:25pm
However it is not required to uses any DLL to be able to use the designer and drag-and-drop custom control on the form.

On the other hand, I don't really understand OP problem with Location property.
This is the answer to a follow-up question which has nothing to do with the question about "enclosed DLLs", which really makes no sense.
In Commercial Purposes, If you have .NET application, then you can use SmartAssembly from redgate[^]; otherwise, you can use Enigma VirtualBox[^] or Oreans Themida with XBundler[^].
CHill60 30-May-15 0:46am
2 years a member and you post an answer to a question that was asked 4 years ago???
In the Solution Explorer in Visual Studio look just below the name of your Project and you should see a 'References' folder. Right click and select 'Add Reference'. Eventually, a dialog will appear (VS2008 takes a long time, VS2010 is quicker). Select the 'Browse' tab and then the 'Browse' button. Navigate to the dll for your controls and double click it.

Alternatively, right click on the Solution Name (in Solution Explorer) and select 'Add' then 'Existing Project..'. Navigate to the project file (*.csproj) for your controls and double click it.
[no name] 18-Apr-11 17:14pm
Oh no! That's how to refer to a library, I know that, but after building (compiling) I want to copy only the EXE file to another computer and use it there, but in fact I also have to copy the dll file following with the EXE file to help the Exe file run well.
Henry Minute 18-Apr-11 17:36pm
You might take a look at ILMerge. ->

I have never used it so don't know how well it works. :)
Henry Minute 18-Apr-11 17:16pm

I misunderstood your question.
[no name] 18-Apr-11 17:58pm
No problem! :), I would like to receive any helps from people and I should say thanks to them anyway!
Thank you! Your suggestion about ILMerge is great to try!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900