ASP.Net 5控制台应用程序入口点 [英] ASP.Net 5 Console Application Entry Point
问题描述
我一直试图在ASP.Net 5中构建控制台应用程序,但是入口点遇到了一些麻烦。我看了以下内容:
可以在CoreCLR上使用异步修饰符标记入口点吗?
和
https://msdn.microsoft.com/zh-CN/magazine/dn913182.aspx 。
当我使用Visual Studio 2015创建控制台应用程序(程序包)时,它会创建以下程序文件
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)
{
}
}
但是我想利用实例将Main作为实例方法,因此我可以添加Program的无参数构造函数并具有一些依赖注入魔术。但是,当我删除 static时Visual Studio给我以下错误:
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 does not have a static 'Main' method suitable for an entry point".
在project.json文件中我注意到以下条目:
I noticed in the project.json file I have the following entry:
"compilationOptions": {
"emitEntryPoint": true
}
如果我将其更改为false。该应用程序会生成,但不会执行Main方法。但这似乎确实叫我的程序构造器。那我是否应该手动调用Main()?我觉得我在这里做错了。我将不胜感激。
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.
推荐答案
DNX平台希望与常规的 Program.Main
入口点。因此,控制台应用程序需要具有静态入口点:
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) { ... }
自RC1以来已更改: https://github.com/aspnet/Announcements/issues/113
It has been changed since RC1: https://github.com/aspnet/Announcements/issues/113
这篇关于ASP.Net 5控制台应用程序入口点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!