[C #] uses Ilmerge to merge the source DLLs into the target EXE (. NET4.6.2)

Source: Internet
Author: User



This article is original article, if reproduced, please indicate the original name, author and website in the obvious location of the webpage, thank you!



This article mainly uses the Microsoft Ilmerge tool to merge the source DLL into the target EXE, so the following tools need to be downloaded:


https://www.microsoft.com/en-us/download/details.aspx?id=17630


Or in Baidu network disk download:


Https://pan.baidu.com/s/1qYyqJCC


The software can be installed with certainty.



After the tool has been installed, use the cmd command prompt to enter the directory using the tool:


CD Files (x86) \microsoft\ilmerge


As shown in the following:






The main usage of the tool is as follows:


/out:filename <primary assembly> [<other assemblies> ...]


As shown in the following:






Open Visual Studio 2017 (or 2015), reference Newtonsoft.Json.dll, and write the following code in the console (the project name is: CONSOLEAPP12):


 
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace ConsoleApp12
{ class Program
    { static void Main(string[] args)
        {
            List<Person> list = new List<Person>()
            { new Person(){ ID = 1, Name = "ABC" }, new Person(){ ID = 2, Name = "XYZ" },
            }; var result = JsonConvert.SerializeObject(list);
            JArray jArray = JArray.Parse(result); foreach(var item in jArray)
            {
                Console.WriteLine($"ID:{(int)item["ID"]},Name:{(string)item["Name"]}");
            }
            Console.ReadKey();
        }
    } class Person
    { public int ID { set; get; } public string Name { set; get; }
    }
}


As shown in the following:






Please download the above source code on the following screen:


Https://pan.baidu.com/s/1pKROMh1


Attention:



①newtonsoft.json.dll is:


Https://pan.baidu.com/s/1o8gJPHo


The dotnetframework of the ②newtonsoft.json.dll must be running above version 4.5 and 4.5.



Click the Run button on the IDE to start the build, as shown in the following files will be generated under the Bin/debug folder:






If you want to run the above program,ConsoleApp12.exe and Newtonsoft.Json.dll are essential , but this looks very awkward, if you can merge into a file, how good ah.



The following work will merge the above two files, using the ILMerge.exe tools described above.



If the test folder on the D drive, the above two files will be merged, as shown in:






Now return to the command prompt form that you just entered, enter the following command:


Ilmerge/ndebug/target:exe/out:d:\test\new_consoleapp12.exe/log D:\test\consoleapp12.exe/log D:\Test\ Newtonsoft.json.dll/targetplatform:v4


Note:/ndebug: As a non-debug version, the release version, if removed, will generate a debug file for the. pdb extension.



/target: As the target platform, the output here is exe



/out: The path and file name of the output after merging



/log: DLL or EXE that needs to be merged, need to include all of the merged EXE or DLL



/targetplatform: Target platform, this time is DotNet4.6.2, so need target platform set to V4



After running, you will be prompted to merge the completed information as shown in the following:






Click on the newly generated new_consoleapp12.exe and the program will run normally as shown in:






We can use ILSpy.exe to view the New_consoleapp12.exe after the merge, as shown in:






As can be seen from the above,ConsoleApp12.exe and Newtonsoft.Json.dll have been merged into New_ConsoleApp12.exe.



[C #] uses Ilmerge to merge the source DLLs into the target EXE (. NET4.6.2)


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.