First, the main purpose of this article is to use the Costura.fody tool to merge the source DLL into the target EXE, so you need to download from any of the following links:
① Download from github address:
Https://github.com/Fody/Costura/releases
② from Baidu network disk download:
https://pan.baidu.com/s/1kV9W34b
③ "recommended" installation tool from NuGet address:
https://www.nuget.org/packages/Costura.Fody/
and install from the Package Manager console in Visual Studio:
Install-package costura.fody-version 1.6.2
Note: The latest version please open NuGet address to get
Second, after installation, Costura.dll, etc. has been quoted, as shown in:
Third, a new solution referencing Newtonsoft.Json.dll, this is borrowed from the previous content "[C #] using Ilmerge to merge the source DLL into the target EXE (. NET4.6.2) "For example, the solution:
Https://pan.baidu.com/s/1jIzjpkU
The code is as follows:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingNewtonsoft.json;usingNewtonsoft.Json.Linq;namespaceconsoleapp12{classProgram {Static voidMain (string[] args) {List<Person> list =NewList<person>() { NewPerson () {ID =1, Name ="ABC" }, NewPerson () {ID =2, Name ="XYZ" }, }; varresult =jsonconvert.serializeobject (list); Jarray Jarray=jarray.parse (Result); foreach(varIteminchJarray) {Console.WriteLine ($"id:{(int) item["Id"]},name:{(String) item["Name"]}"); } console.readkey (); } } classPerson { Public intID {Set;Get; } Public stringName {Set;Get; } }}
The referenced Newtonsoft.Json.dll is shown in the previous picture.
Four, click the Run button, and then under the Bin/debug folder to see the file can be generated as follows:
As can be seen from the film, the resulting file does not contain Newtonsoft.Json.dll and Costura.dll is not generated, only three files.
We can delete ConsoleApp.exe.config and consoleapp12.pdb files, leave ConsoleApp12.exe files,ConsoleApp12.exe can run alone .
We can use ILSpy.exe to view the ConsoleApp12.exe just after the build, as shown in:
As you can see from the above, you can use Costura.fody to merge the source DLLs into the target EXE.
[C #] using Costura.fody to merge source DLLs into Target EXE