What is DNX?

Comments 10

Share to social media

Microsoft have been doing a great deal of innovation in the .NET space over the last year, and vast quantities of this source code has now been provided open-source on GitHub. .NET is finally starting to become portable onto other platforms such as Linux and OSX using just Microsoft-supported technology. Not so long ago, you could only run on Linux by using a technology such as Mono, but now a cut-down, open-sourced version of the .NET runtime, the CoreClr, is starting to become fully functional on both Linux and OSX.

DNX, a Dot Net eXecution environment, contains all of the code that is required to bootstrap and run an application. It includes the compilation system, SDK tools and the native CLR host, with NuGet packages being used to access assemblies that are referenced by the application. This system gives us the ability, for the first time ever, to deploy applications merely by copying them. Each application can reside in its own directory which will contain the NuGet packages for all of its dependencies.

When you install VS 2015, you get a version of DNX installed onto your machine. If you start a command prompt and run DNVM, the DNX version manager, you can see the variants of the CLR that are initially installed.

2261-1-7618279f-5609-4513-a5d4-8b16ce6fc

Using a simple cs code file which writes a message, and a simple project file to list the dependencies:

2261-1-99802370-36d3-4246-aba3-24cf57455

I can choose a version of the CLR, and then run that version of the CoreClr.

2261-1-de1f9005-72bc-493b-bb9c-75ebec484

The restore command shown above downloaded the packages that the application needs, and you might wonder where the packages are stored. By default they go into a .dnx\packages folder under your user – so for me they were at C:\Users\clive.tong\.dnx\packages.

If I go to that location and clean things out then, when I run my application, I get notified of the missing packages.

2261-1-1425ca0c-2016-439c-9dab-9e26046d8

Running the restore command fetches them, and my application starts working again.

2261-1-c5f603a3-d119-4e0b-a596-a9ea5cf9b

Inside VS2015, there is a way to produce a packaged console application just like the example above called ‘Console Application (Package)’.

2261-1-c46019ef-c881-4736-a730-dd7e4efdd

However, the main focus is on ASP.NET web applications that sit on top of this new framework. A choice of ASP.NET Web Application leads me to a number of ASP.NET 5 preview templates:

2261-1-57e6c0ac-b505-4c27-add0-a85228c83

Picking, for example, Web Application, produces a demo web site that sits on top of the DNX framework.

Notice that the project file is in the DNX-friendly JSON format.

2261-56781840-381e-407c-9840-dfdde60f2ad

The framework choice is now slightly hidden on the project properties page. However, if I go to the properties page for the WebApplication1 project note (highlighted above), on the properties tab I can control the DNX version for the solution.

2261-462e531c-78e2-4d94-8496-ecfdbf11aad

If you have difficulty trusting tooling like me, then you can try changing this setting to pick the core clr instead.

2261-8cea65ef-ea3d-4523-9827-2bd9fb2cde7

Then start the solution running and use the Debug/Modules window to see which version of the CLR is loaded.

2261-735f163f-9593-42fe-9c1d-98396023109

I should also point out that you can choose if the application is hosted inside IIS Express, which it is by default.

2261-c9ceb88f-d201-41a3-9cee-9568924f837

Choosing web runs the application inside a standalone web server.

2261-1-3705bd49-d1e2-4716-b77e-2c4cdde28

Which is in turn achieved by a set of commands embedded inside the project json file.

2261-9b341117-e190-4b95-8331-cdff0437378

Having done that, and having got a functioning site running, you might be wondering how you can then profile the results. This is how I became interested in DNX. I have to confess that I don’t lie awake at night dreaming about hosting ASP.NET sites on Linux boxes. However, I do admit to being rather engrossed in trying to make sure that ANTS Profilers keep pace with all the new things that Microsoft’s .NET team introduce, such as DNX and Async. I’m not actually admitting that ANTS profiler is my baby, but I’m currently one of those holding the baby and helping it grow. It is my job to make sure that you can look at performance and memory issues easily when you are developing DNX applications.

2261-1-113ac130-6b80-456c-bb28-ee826be6e

To make it possible to look at performance for these applications, we have added a new project type within both the ANTS Performance and Memory Profilers. This manifests itself in a really simple way – there is a new tab named ASP.NET 5 that allows you to point ANTS at the relevant project.json file. You can then choose the framework to use for running the application.

“Start Profiling” will then launch the application. If you have chosen “Launch using IIS Express” under the start options then it will be hosted inside iisexpress, or otherwise as a standalone web application which will be executed using the web command inside the project file.

2261-6f42b06d-d9a5-4685-8da1-cd2cb2ff741

With this new type of project, the profiling experience should be much the same as normal. The new web projects are using Roslyn to do the compilation, which means that the system no longer compiles assemblies to temporary directories, but uses the Roslyn framework to generate in-memory assemblies. When the source code is edited, the system can seamlessly recompile the changed application making the development experience a lot richer.

When you look at profiled output, you’ll instantly notice loads of async methods in the new framework, so the Performance Profiler’s async view gets a great workout.

2261-a08e60d1-eed8-4441-980f-b3a52b154c2

Naturally, you can still examine all the SQL Calls that the application makes, and see how long they take, but you’ll be pleased to know that the Query Plan can be also displayed graphically to let you know not only which SQL Queries are slowing things down but why they are slowing things down.

You might imagine that the task of keeping Ants Performance and Memory Profiler up-to-date involves having plenty of time to stare out of the window and chat to colleagues at the water cooler. In fact, .NET is a moving target. There are always new features being introduced, and we have to be sure of being able to profile them. Our customers expect us to be able to profile anything in .NET and when Microsoft announce a whole raft of new features we sigh and reckon we have a busy time ahead to keep up! However, DNX is something rather special and we found being able to write applications that didn’t require an installer to be a giant step forward. We hope that many of you will find ANTS profilers useful for profiling these DNX applications. We’ve been able to deliver this functionality simultaneously in both APP and AMP thanks to work done earlier in the year to improve the way we share code between the two profilers – and hopefully in future we’ll be able to continue to deliver functionality to both profilers at the same time.

There are also a number of minor features in APP, including async support in .NET 4.6, an average time column in the methods view, support for the pure-managed Oracle driver and some improvements to the query plan UI. And, as ever, there’s a large number of bug fixes and general improvements. We feel quite smug about it all, but if you’re a bit hesitant, no worries because you can try both ANTS Performance Profiler and ANTS Memory Profiler for 14 days free.