简体   繁体   English

ASP.Net 5控制台应用程序入口点

[英]ASP.Net 5 Console Application Entry Point

I've been trying to build a console application in ASP.Net 5 and am having some trouble with the entry point. 我一直试图在ASP.Net 5中构建控制台应用程序,并且在进入点方面遇到了一些麻烦。 I've looked at the following: Entry point can be marked with the 'async' modifier on CoreCLR? 我看了以下内容: 入口点可以在CoreCLR上用'async'修饰符标记吗? And https://msdn.microsoft.com/en-us/magazine/dn913182.aspx . https://msdn.microsoft.com/zh-CN/magazine/dn913182.aspx When I create a Console Application (Package) with Visual Studio 2015 It creates the following Program File 当我使用Visual Studio 2015创建控制台应用程序(程序包)时,它将创建以下程序文件

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: 但是,我想利用实例将Main作为实例方法,以便可以添加Program的无参数构造函数并具有一些依赖注入魔术。但是,当我删除“静态” Visual Studio时,出现以下错误:

"Program does not have a static 'Main' method suitable for an entry point". “程序没有适合入口点的静态'Main'方法”。

I noticed in the project.json file I have the following entry: 我在project.json文件中注意到我有以下条目:

"compilationOptions": {
    "emitEntryPoint": true
}

If I change this to false. 如果我将其更改为false。 The application builds but it does not execute the Main method. 该应用程序会生成,但不会执行Main方法。 But it does seem to call my Program Constructor. 但这似乎确实叫我的程序构造器。 Am I then supposed to just call Main() manually? 那我是否应该手动调用Main()? I feel like I'm doing something wrong here. 我觉得我在这里做错了。 I would appreciate any help. 我将不胜感激任何帮助。

The DNX platform wants to be compatible with regular Program.Main entry points. DNX平台希望与常规Program.Main入口点兼容。 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 自RC1以来已更改: https : //github.com/aspnet/Announcements/issues/113

Related: Runtime services no longer get injected into DNX console app (RC1) 相关: 运行时服务不再注入DNX控制台应用程序(RC1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM