In Rider, after making a simple Hello World console project, I can choose between one of two output types: Console Application and Class Library. The former makes a runnable exe and a runnable DLL, while the latter makes a non-runnable DLL. The runnable DLL obviously needs to be ran through the dotnet CLI driver.
What would be the correct terminology to distinguish between the former and latter DLLs? I am uncertain what the differences are, besides one being runnable and one not.
Also, why is the runnable DLL 30x smaller in size than the exe?
CodePudding user response:
Unrelated to the IDE of your preference, ie. even doing this from CLI with dotnet new console -n myapp
and then running a dotnet build
would (now currently with .NET6) produce a myapp\bin\debug\net6.0
dir in which you get a platform specific exe and cross-platfrom dll.
The exe is a platform specific (OS/CPU arch) executable of your app carrying all the stuff required for your OS/platform (that's the 30x weight you ask about, not sure what's in it really) and the dll on the other hand would work on any of platforms if ran through the .NET Runtime (ie. dotnet myapp.dll
).
You can run the .exe (on your current OS/CPU arch) by invoking it directly: .\myapp.exe
You can run the .dll on any machine with .NET Runtime (the driver as you speak) (in same version of your build) installed with dotnet CLI in path variable as: dotnet myapp.dll
.
The former dll is a cross-platform binary of your application which can be executed with the appropriate .NET Runtime and latter is a .NET library dll which is not of <OutputType>Exe<OutputType>
(but library) and is not intended to be executed (does not have a Main() somewhere in it) but is intended to be referenced by other DLLs (or projects as you will).
Read more about platform specific exes here: https://docs.microsoft.com/en-us/dotnet/core/deploying/#produce-an-executable
You can read more about publish exes here: https://docs.microsoft.com/en-us/dotnet/core/deploying/#publish-framework-dependent
The exe output is forced by the <OutputType>Exe</OutputType>
inside your .csproj project file.
Also, you might consider learning about Single-File-Executables (here: https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file/overview) where you can even pack the .NET Runtime in it, so your target machine does not even need to have dotnet
on it (in the path variable).