Skip to main content

Difference between “dnx run” and “dotnet run”

Earlier I posted about dotnet cli, which is a new command line tool which is going to replace DNX commands and it will be part of ASP.NET 5 RC 2 release. Since ASP.NET 5 is now ASP.NET Core 1.0, so not quite sure what would be the release name now but irrespective the name, it is expected to release this month only. I was playing with dotnet commands and noticed that dotnet run command is different from dnx run command. So in this post, you will see the difference between “dnx run” and “dotnet run”.

Difference between “dnx run” and “dotnet run”

To understand the difference, first create 2 console applications “HelloWorldDnx” and “HelloWorldDotnet” using VS 2015. You can create console application via File -> New -> New Project and select console application under web.

Create New Console Application Visual Studio 2015

Below image shows the folder structure just after creating the applications.

Console application folder structure

Notice, there is no bin folder. By the way, for ASP.NET core 1.0, bin folder location is changed. Read Quick summary of what’s changed in ASP.NET Core 1.0.

Now let’s open two different command prompt and run dnx run and dotnet run commands respectively.

Difference between dnx run and dotnet run

And now let’s visit both the folders. You will notice that “bin” folder is created only for the console application for which dotnet run command was executed. Why no bin folder for console application executed via dnx run?

The reason is, for DNX commands, roslyn compiler is sitting inside the DNX process. Which loads the code, compiles in memory and immediately launch the compile binaries. And that’s why DNX is fast. But the problem is as and when DNX shuts down, compiled binaries are gone. Since it compiles in memory, therefore “no bin folder”.

On the other hand, dotnet run is more like a traditional method. When dotnet run command is executed, it internally executes dotnet compile which in turn calls the language compiler exe (like cse.exe for c#) that compiles your code and creates bin folder and copies the managed code to disk. You can check it yourself via executing,

dotnet -v run 

That’s it.

Bonus Tip:
There is one more advantage of dotnet commands over dnx commands that using dotnet command, you can compile your application native binaries. Following command will compile to IL binaries.

dotnet compile

To compile to native binaries,

dotnet compile --native

That’s all folks. Keep visiting this blog and share this in your network. Please put your thoughts and feedback in the comments section.

2 thoughts on “Difference between “dnx run” and “dotnet run”

Leave a Reply

Your email address will not be published. Required fields are marked *

sixteen − 3 =