0

Possible Duplicate:
.NET windows application, can it be compressed into a single .exe?

I have a project and I am using a lot of .dll files in this project. When i try the run my project on another computer it's not working. Because i am using only .exe. I think I have to make setup project. But I want to run my program without making setup project. How can I embed .dll files into my exe? I am using Visual Studio 2010. By the way sorry for my English but google translated English worse than mine. Thanks.

Community
  • 1
  • 1
cvwerfwe
  • 15
  • 3

3 Answers3

1

You need just copy your dll file with exe file into the same directory. and you can use the ILMerge util

you can download it from msdn

Sergey K
  • 4,071
  • 2
  • 23
  • 34
1

Use ILMerge.exe and you can merge your EXE and DLL together.


You can also use netz.exe as an alternative EXE compressor & packer.

Brian Chavez
  • 8,048
  • 5
  • 54
  • 47
0

Just right-click your project in Visual Studio, choose Project Properties -> Resources -> Add Resource -> Add Existing File… And include the code below to your App.xaml.cs or equivalent.

public App()
{
    AppDomain.CurrentDomain.AssemblyResolve +=new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}

System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    string dllName = args.Name.Contains(',') ? args.Name.Substring(0, args.Name.IndexOf(',')) : args.Name.Replace(".dll","");

    dllName = dllName.Replace(".", "_");

    if (dllName.EndsWith("_resources")) return null;

    System.Resources.ResourceManager rm = new System.Resources.ResourceManager(GetType().Namespace + ".Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly());

    byte[] bytes = (byte[])rm.GetObject(dllName);

    return System.Reflection.Assembly.Load(bytes);
}

Here's my original blog post: http://codeblog.larsholm.net/2011/06/embed-dlls-easily-in-a-net-assembly/

Lars Holm Jensen
  • 1,645
  • 1
  • 12
  • 14