views:

75

answers:

5

I have a console application and two class library projects.

The console application has to project references to the class library projects.

When I build, it generates DLLs for these two projects. Do I have to include these with my console applications exe file? Is there a way I can make it so I don't have to include these 2 dlls?

Ideally, I'd like to have a single exe.

+5  A: 

You must include any referenced assemblies as they are dependencies of your application.

That being said, however, Microsoft offers a tool called ILMerge that will allow you combine the dependency assemblies with your executable to create one, all-inclusive, executable assembly that you can ship to customers.

Andrew Hare
+2  A: 

Check out ILMerge.

JP Alioto
A: 

You should be able to accomplish by selecting your references and setting the "Copy Local" property to false.

Joel Etherton
Is this true? Does this work?
KingNestor
That will copy the .dlls into (e.g.) the Debug/ output folder, you'd still have to ship the dlls and the exe when distributing the app.
nos
That's how I do it for my binary WinForms applications.
Joel Etherton
@nos: That's not how it behaves for me. Maybe I'm just a freak of nature but I have a WinForms executable with 8 references in the local projects, all set Copy Local to "false". I only deploy the .exe and it works like a charm.
Joel Etherton
That is because it embeds this information into the project.This can happen if you define a connection string to your application instead of using the app.config / web.config file.
JonH
@JonH: Give it a try. If you have config information you still need to ship a separate config (but this can be worked around using compiled .resx files). I just verified it because you people have me thinking I'm crazy. I just shipped an exe with a config to a server that has never even seen this application (I thought maybe my success was masked by files in the GAC, but it wasn't), and it worked splendidly.
Joel Etherton
@Joel Etherton: I do not believe this is true. It is not consistent with documentation and I cannot duplicate this. I get the exception System.TypeInitializationException because of the missing libraries.
AMissico
+1  A: 

You can merge the assemblies into one, using ilmerge, otherwise you'll have to deploy the exe file and the dlls. e.g. you can run a command like

ilmerge /target:winexe /out:MyProg.exe Program.exe ClassLib1.dll ClassLib.dll

Visual Studio provides no built-in way to do this, so you'd have to run the above command manually,as a Post Build event, or add it manually to your .csproj file.

nos
A: 

Be careful with ILMerge and make sure you understand the performance implications of going this route.

Alex