Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a vNext console application?

I installed Visual Studio 2015 RC to try out the ASP.Net vNext templates. In the "Web" section, I have noticed a console application that appears as

enter image description here

I decided I would mess around with it and I found some interesting points:

  • The default template does not specify Main() as static.
  • Many assemblies such as System.CodeDom and System.Net are not available.
  • Many methods such as System.Console.ReadKey cannot be used.

What are these vNext console applications? Why the restrictions and what are the uses of them?

like image 971
James Parsons Avatar asked Jun 16 '15 00:06

James Parsons


2 Answers

Answers

What is a vNext console application?

It's a console application that runs within the new .NET runtime environment (DNX).

Why the restrictions and what are the uses of them?

The restrictions occur because you are targeting .NET Core (dnxcore50) instead of (or in addition to) the full .NET Framework (dnx451.) The use of those restrictions, as far as I know, is to allow cross-compatibility with a lot of different operating systems. That is, .NET Core has less functionality than the full framework does, because it is easier to be compatible with many systems that way. Overtime, those restrictions may fall away as more in made fully cross platform.

The default template does not specify Main() as static.

DNX comes with Microsoft.Framework.ApplicationHost. This default application host "knows how to find a public void Main method. This is the entry point used to set up the ASP.NET hosting layer..." It also still knows how to find the traditional static void Main method. An advantage of an instance Main method is that it lets us ask the runtime environment to inject services into our application.

Many assemblies such as System.CodeDom and System.Net are not available. Many methods such as System.Console.ReadKey cannot be used.

System.Console.ReadKey is available in dnx451 but not in dnxcore50. That's also true for System.Net the last time I checked. So, if you want to use those, make sure to target dnx451 instead of dnxcore50.

Want to remove the restrictions? Just delete the dnxcore50 entry from your project.json file. Then you'll only be targeting the full framework without restrictions.

See Also

https://msdn.microsoft.com/en-us/magazine/dn913182.aspx

'Console' does not contain a definition for 'ReadKey' in asp.net 5 console App

Using System.Net.Mail in ASP NET MVC 6 project

like image 159
Shaun Luttin Avatar answered Sep 27 '22 19:09

Shaun Luttin


Those console applications are leveraging the new .NET execution environment (DNX, previously KRE). It includes a new project system and allows you to target different versions of the CLR.

One of those versions is CoreCLR which is a slim version of .NET. This version is modular and its libraries are distributed as a bunch of NuGet packages. You may need to include some additional packages when targeting .NET Core (dependencies section on your project.json file).

Nevertheless, some of the limitations may arise from the fact that not all the APIs are already migrated to .NET Core or from the fact that they won't be, since the API surface is smaller on .NET Core.

like image 31
lgoncalves Avatar answered Sep 27 '22 19:09

lgoncalves