【问题标题】:No suitable 'Program' type for an entry point没有适合入口点的“程序”类型
【发布时间】:2016-01-05 15:58:07
【问题描述】:

最近每晚 RC2 版本的更新似乎改变了程序的启动方式。自更新以来,我现在在运行以下命令时出现错误。

// "commands": {
//      "web": "Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:1287"
// }

dnx --watch web

'Microsoft.AspNet.Server.Kestrel' does not contain a 'Program' type suitable for an entry point Stopped listening.

Startup.cs 编译并具有以下方法。

public class Startup
{
    public void ConfigureServices(IServiceCollection services, IHostingEnvironment env)
    { ... }

    public void Configure(IApplicationBuilder app, IApplicationLifetime lifetime)
    { ... }
}

需要做什么才能让程序以最新的nightly 构建启动?

这是一个重现该问题的示例。 https://github.com/roydukkey/moist/tree/stackoverflow-34615917

sdk: v1.0.0-rc2-16357

【问题讨论】:

    标签: asp.net-core


    【解决方案1】:

    aspnet/Hosting#521 中,已删除多个入口点。

    以前,我们有多个 Web 应用程序入口点,包括主机 (Microsoft.AspNet.Hosting)、服务器(例如 Microsoft.AspNet.Server.Kestrel)和应用程序本身(例如 Startup.cs)。我们已经删除了主机和服务器中的入口点,因此唯一前进的入口点来自应用程序。这将需要更新project.json,包括将compilationOptions 下的emitEntryPoint 设置为true,并将commands 设置为指向启动程序集。 aspnet/Announcements#131

    要解决此问题,commands 设置需要指向程序集,而不是列出以前有效的服务器配置。此外,需要启用emitEntryPoint 设置。这两个设置都是从​​project.json 设置的。

        "compilationOptions": {
            "emitEntryPoint": true
        },
    
        "commands": {
    -       "web": "Microsoft.AspNet.Server.Kestrel"
    +       "web": "Web"
        }
    

    具体的服务器配置现在位于hosting.json。以下只是一个示例配置。

    {
        "server": "Microsoft.AspNet.Server.Kestrel",
        "server.urls": "http://localhost:1234"
    }
    

    请参阅roydukkey/moist/tree/stackoverflow-34615917 以查看整个问题的工作流程。

    【讨论】:

      【解决方案2】:

      您需要添加一个static 类,其中包含一个静态Main 方法。从那里,您需要托管它。如下:

      public class Program
      {
          public static void Main(string[] args)
          {
              var configuration = WebApplicationConfiguration.GetDefault(args);
      
              var application = new WebApplicationBuilder()
                          .UseApplicationBasePath(Directory.GetCurrentDirectory())
                          .UseConfiguration(configuration)
                          .UseStartup<Startup>()
                          .Build();
      
              application.Run();
          }
      }
      

      不确定是否强制,但您可能还需要在 project.json 中包含以下内容:

      "compilationOptions": {
          "emitEntryPoint": true
      }
      

      完整版:

      {
          "version": "1.0.0",
          "compilationOptions": {
              "emitEntryPoint": true
          },
          "dependencies": {
              "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc2-*",
              "Microsoft.AspNet.Hosting": "1.0.0-rc2-*"
          },
          "frameworks": {
              "dnx451": {},
              "dnxcore50": {}
          }
      }
      

      【讨论】:

      • 我正在使用“Microsoft.AspNet.Server.Kestrel”:“1.0.0-rc2-*”等
      • 解决方案应该是相同的(除非有重大的新变化不会让我感到惊讶 :D),试一试并应用您的版本。
      • “WebApplication”不包含“运行”Web.DNX 4.5.1 的定义
      • 嗯,他们可能已经迁移到 dotnet CLI。这也可能给你一个想法:github.com/davidfowl/dotnetcli-aspnet5/tree/…
      • 啊,不。 RC2 中的 API 已更改。按照这个:github.com/davidfowl/dotnetcli-aspnet5/blob/…
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-06
      • 2012-04-21
      • 2014-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多