Last updated .
A google search for DNX reveals that it's something about digital nomads - it-savvy people living and working out of 3rd world countries. But it's also the acronym for the next major development on the .Net platform. It is short for ".NET Execution Environment". Somewhat ironically, Microsoft is working hard to relieve itself of .Net and make it open source and cross platform. DNX is both an SDK and a runtime environment that comes with everything needed to build and run .NET applications. Not only on Windows, but also on Linux and Mac.
A survey of the available info suggests there are essentially these three motivations behind DNX:
With these motivations, Microsoft created a
light-weight and cross-platform version of the
.NET framework, called
DNX - the .Net eXecution environment - contains everything required to bootstrap and run a .Net app. It includes the compilation system, SDK tools and the native CLR host, with NuGet packages being used to get assemblies referenced by the solution.
DNX is installed with Visual Studio 2015. At the time of writing, the latest version is v1.0.0-rc1-15540.
With RC1 installed, I can make a DNX project with Visual Studio. There are three project templates to choose from - all grouped under the Web Category. This is probably due
to the fact that the development of a new DNX-based version of ASP.Net has been the driving force. Still, it is a bit surprising to see a
The project composition as shown in solution explorer sure looks outlandish. That structure is an almost direct reflection of the file structure on disc. One thing to notice is the
lack of a project file in the traditional sense. Instead, the
What does that project file contain?
project.json
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
{
"version": "1.0.0-*",
"description": "DNXConsole02 Console Application",
"authors": [ "Niels" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
},
"commands": {
"DNXConsole02": "DNXConsole02"
},
"frameworks": {
"dnx451": { },
"dnxcore50": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Console": "4.0.0-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
}
}
Let's try writing some code:
program.cs
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
using System;
namespace DNXConsole02
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello DNX!");
Console.ReadLine();
}
}
}
As you'd expect this code compiles just fine and I can run it from within Visual Studio as usual.
But there is no output to be found on disc. I found a
I selected the default target DNX and clicked
The contents of the
And what does that command file contain, then? This:
DNXConsole02.cmd
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
@echo off
SET DNX_FOLDER=dnx-clr-win-x86.1.0.0-rc1-update1
SET "LOCAL_DNX=%~dp0runtimes\%DNX_FOLDER%\bin\dnx.exe"
IF EXIST %LOCAL_DNX% (
SET "DNX_PATH=%LOCAL_DNX%"
)
for %%a in (%DNX_HOME%) do (
IF EXIST %%a\runtimes\%DNX_FOLDER%\bin\dnx.exe (
SET "HOME_DNX=%%a\runtimes\%DNX_FOLDER%\bin\dnx.exe"
goto :continue
)
)
:continue
IF "%HOME_DNX%" NEQ "" (
SET "DNX_PATH=%HOME_DNX%"
)
IF "%DNX_PATH%" == "" (
SET "DNX_PATH=dnx.exe"
)
@"%DNX_PATH%" --project "%~dp0src\DNXConsole02" --configuration Release DNXConsole02 %*
In this script, if I read it correctly, every line except the last one is about establishing a path to a
That
The conclusion to draw from all this can only be that the "Publish" operation does not produce any binary output by itself. Instead, the source code is copied
to a publish folder together with dependencies and the
Targeting DNX 4.5.1 and DNX Core 5.0, you can quickly meet some stumbling blocks writing code. It's one thing that Windows-specific .Net libraries such as
In the intellisense, that method has a yellow warning icon on it, and the pop-up tip tells me that member is not available on Core 5.0. If I complete the statement, my project won't compile.
The tip told me that I can use the navigation bar to switch context. The navigation bar is the name for the dropdowns at the top of the code editor window. In the leftmost one I can
pick one of the options
It would be instructive to see which assemblies are actually loaded in the process when the console app is run from Visual Studio. There are some settings on the project property page that
provide a clue: Under the
The
Let's see what it looks like when running under 1.0.0-rc1-update1, .Net Core, x64:
Again, the
DNX comes with a set of tools to manage it all on the client machine. The management central is the
As you might gather from the command names, dnvm is used to manage the dnx local installation.
With DNVM, you can specify which version of the .NET Execution Environment to use at the process, user, or machine level.
Another tool is
Program.cs
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
using System;
namespace DNX_Testing
{
public class MyClass
{
public static void Main(string[] args)
{
Console.WriteLine("I am dynamically compiled!");
Console.ReadLine();
}
}
}
project.json
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
{
"version": "1.0.0-*",
"description": "My DNX Console Application",
"authors": [ "Anonymous" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
},
"commands": {
"DNXTest": "DNXTest"
},
"frameworks": {
"dnx451": { },
"dnxcore50": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Console": "4.0.0-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
}
}
Opening a command prompt in that
2016 by Niels Hede Pedersen