Run exe unless make setup (embed dll to exe) [duplicate]
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.
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
Use ILMerge.exe and you can merge your EXE and DLL together.
You can also use netz.exe as an alternative EXE compressor & packer.
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/
精彩评论