简体   繁体   中英

C# How to include DLL from Nuget in my EXE

How do I include a DLL package from NuGet as part of my EXE? This is to have a standalone EXE and not worry about extra files outside it.

I'm building a simple C# exe targeting the .NET Framework 4.7.2. I downloaded CommandLine (Command Line Parser) from NuGet. Package is here: https://github.com/commandlineparser/commandline

I want to include this DLL in my EXE.

Thanks in advance.

If you have a specific DLL, not from NUGET, then you will add it manually.

add a reference to the dll to your project's References folder. Then any source file that accesses the DLL namespace you want will need to include a line to include the namespace. You will have to have documentation of the DLL.

using My.DLL.Namespace.Subspace; //Or whatever...

If it is a package managed by NUGET, you should just have to use NUGET to install it. The issue may be that you are using a repository, and just pulling from a colleageus (spelling?) setup, and for soem reason they have not commited the files. I don't think that is necessarily the issue though, as I recall having read somewhere that NUGET would notice the missing files and download them.

EDIT: I miss understood your question. You want the DLL to be compiled INTO your Executable file. I am not certain how to do this. My initial (but untested) reaction is to right click on the DLL, and it might be possible to change the inclusion from "Copied", or "Always replaced" to "Compiled" and that JUST MIGHT include it into your executable.

Not supposed to link to outside soruces... but here is this source from the Microsoft forum.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/5c428cab-35f9-43c5-a516-05226fc0cb8c/how-to-compile-a-dll-into-my-exe-file?forum=vbgeneral

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM