Before we go ahead, some key points:
Executable file:
- An executable file contains biinary machine code (ones and zeros) that has been compiled from source code.
- This low-level code instructs the computer's CPU on how to run a program
- For windows it's .exe files, for mac it's .app and for linux/unix it's called binary executables
.NET runtime (CoreCLR {Common Language Runtime}):
- It takes IL(Intermediate Language ) code that is obtained from language compiler(Roslyn for C#) and converts it to executable machine code (.exe)
Difference between dotnet run and dotnet publish
- dotnet run
- It is used in the development phase of the .NET application
- How it works
- It compiles the source code that can be run not by the OS but can be run by .NET runtime
- i.e. it signals to compile the source code using a compiler(Roslyn etc.) that converts the code to IL which can be run by .NET runtime
- .NET runtime(CoreCLR) then converts that code into machine code with its JIT(just-in-time) ability to compile IL into machine code(executable .exe files)
- dotnet publish
- It is used when you want to prepare your application for deployment
- After you are finished developing an application and want to share it, you use dotnet publish to generate the necessary files
- How it works
- This is used when you want to package your application along with all its dependencies into a directory that can be deployed and run on a target system without requiring the .NET SDK to be installed
- It compiles the application and produces a set of files (including the executable, DLLs, and other necessary files) in a directory structure that can be directly deployed.
- Here is the output of dotnet publish
* dotnet xyz.dll // this is how dotnet can run dll files
Comments
Post a Comment