Embedding DLL's into .exe in in Visual C# 2010

前端 未结 8 2316
臣服心动
臣服心动 2020-12-14 10:31

I\'m working on a C# program that uses iTextSharp.dll and WebCam_Capture.dll. When I build the program, it creates executable in the debug folder and it also copies these tw

8条回答
  •  清歌不尽
    2020-12-14 11:10

    I know that topic is old but i'll write it for future persons that will want to use it.

    i base on code by userSteve.

    i would suggest to change this.

    String thisExe = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
    

    into this

    String thisExe = System.Reflection.Assembly.GetExecutingAssembly().EntryPoint.DeclaringType.Namespace;
    

    that way it would work even if namespace is different than assembly name

    also if you want to use DLL from directory you can use it like that (directory Resources as Example)

    String resourceName = thisExe + ".Resources." + embeddedAssembly.Name + ".dll";
    

    if you still can't find where place this code in C# Form application paste it inside file "Program.cs" above line:

    Application.Run(new Form_1());
    

    and below lines:

    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    

提交回复
热议问题