Method of merging WinForm program (with multiple unmanaged DLLs) into one EXE

Source: Internet
Author: User

Developers often refer to some third-party DLLs, and then compile the generated EXE files can not be separated from these DLLs run independently.

Ilmerge can combine a managed DLL with an EXE to generate a new EXE, but when we use an unmanaged DLL in the project, that is, when a third-party DLL is used, the merge succeeds but fails to run, prompting " not a valid Win32 application "

At this time we need to use a tool called Fody.costura. The Fody.costura is a plug-in in a fody framework that can be installed into the VS project through NuGet. Once installed, you can package the DLLs (or even PDB) files that your project depends on in the EXE file.

How to use
    1. In VS, Costura.fody is installed through NuGet for the target EXE project.
    2. Restart vs after successful installation, then regenerate

After the rebuild is completed, the newly generated EXE file is found in the output directory of the project, and you will also find those DLLs still exist under the output directory. But don't worry, this exe has been able to run independently. You can delete all these DLLs and then run EXE to try again.

In addition, Fody.costura supports some advanced features, such as:

    • Temporary assembly file: Automatically extracts the DLL from the EXE to the folder system before running the EXE, and then loads the DLL in a regular manner.
    • Merging unmanaged DLL:Fody.Costura can merge unmanaged DLLs, but they do not automatically fit. If your program involves an unmanaged DLL, you need to show it by modifying the Fody.costura configuration file to tell it which unmanaged DLLs you want to merge.
    • Preloaded DLL:Fody.Costura can help you preload some DLLs when the program starts, and you can even specify the order in which these DLLs are loaded.

These advanced features require you to modify the Fody.costura configuration file to achieve, the specific steps can refer to its official documentation.

Method of merging WinForm program (with multiple unmanaged DLLs) into one EXE

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.