[C #] using Costura.fody to merge source DLLs into Target EXE

Source: Internet
Author: User

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

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.