In C#/.Net the file format of an Assembly is both an EXE file with the .exe
file extension and a DLL file with the .dll
file extension.
Regarding a Library in C#/.Net
- Is the file format of a Library only a DLL file with the
.dll
file extension? - Or is the file format of a Library both a DLL file with the
.dll
file extension and an EXE file with the.exe
file extension?
CodePudding user response:
It depends.
In C#, this depends on the compiler and framework settings used. When targeting the .NET Framework, a class library is compiled to a .dll file and an application is compiled to an .exe file. Technically, both file formats are very similar, the only difference is that the exe file contains a main entry point and the code to load the .NET runtime.
When targeting .NET core (or .NET 5.0 or later), this changes a bit: All assemblies are compiled to .dll files. Applications get an additional .exe file with the same name that is the platform-specific loader for the runtime (or the full runtime, depending on the build settings). You'll notice that the exe files for .NET core are always quite small and similar in size. (When targetting linux, this file has no extension at all)
So a class library is always compiled to a .dll file, and an application can be both. Note that C# / .NET does allow using an application as library.
CodePudding user response:
A assembly is just a collection of compiled code. It can be an executable, or a library. Libraries are always .dll
. Executables are always .exe
.
Where it might get fuzzy for some is things like web apps. Those will not contain an executable when you build them, because technically the hosting system, IIS for example, will have its own EXE that will run your libraries within itself.