1

I've been trying to build a console application in ASP.Net 5 and am having some trouble with the entry point. I've looked at the following: Entry point can be marked with the 'async' modifier on CoreCLR? And https://msdn.microsoft.com/en-us/magazine/dn913182.aspx. When I create a Console Application (Package) with Visual Studio 2015 It creates the following Program File

public class Program
{
    public static void Main(string[] args)
    {
    }
}

However I want to utilise the instance have Main as an instance method so I can add a parameterless constructor of Program and have some Dependency Injection magic.. However when I remove "static" Visual Studio gives me the following error:

"Program does not have a static 'Main' method suitable for an entry point".

I noticed in the project.json file I have the following entry:

"compilationOptions": {
    "emitEntryPoint": true
}

If I change this to false. The application builds but it does not execute the Main method. But it does seem to call my Program Constructor. Am I then supposed to just call Main() manually? I feel like I'm doing something wrong here. I would appreciate any help.

Community
  • 1
  • 1
dontbesorry80
  • 567
  • 1
  • 6
  • 12
  • *“a console application in ASP.Net 5”* – That sounds a bit weird… I think the only way to have a “console-like” experience with DNX is with the commands functionality. Take a look at the code behind [dnx ef](https://github.com/aspnet/EntityFramework/blob/dev/src/EntityFramework.Commands/Commands/Program.cs) as an example. – poke Jan 08 '16 at 08:19
  • Here is the quick introduction to console apps in ASP.Net 5 http://docs.asp.net/en/latest/dnx/console.html. It seems to execute the Main method if I remove the "string[] args" parameter which is even wierder.. – – dontbesorry80 Jan 08 '16 at 09:42

1 Answers1

2

The DNX platform wants to be compatible with regular Program.Main entry points. Therefore console apps require to have a static entry point:

public static void Main(string[] args) { ... }

It has been changed since RC1: https://github.com/aspnet/Announcements/issues/113

Related: Runtime services no longer get injected into DNX console app (RC1)

Community
  • 1
  • 1
Henk Mollema
  • 44,194
  • 12
  • 93
  • 104