Asp.Net Core:程序不包含适用于入口点的静态"Main"方法 [英] Asp.Net Core: Program does not contain a static 'Main' method suitable for an entry point

查看:278
本文介绍了Asp.Net Core:程序不包含适用于入口点的静态"Main"方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将基于Onion Architecture设计方法的Asp.Net WebApi项目移植到Asp.Net Core.但是,当我构建类库时,编译器正在Program.cs中寻找静态Main方法,并且得到:

I am trying to port my Asp.Net WebApi project, based on the Onion Architecture design approach, over to Asp.Net Core. However, when I build my class libraries, the compiler is looking for the static Main method in Program.cs and I am getting:

C:\ Projects \ Some \ src \ Some.Core \ error CS5001:程序不包含 适用于入口点的静态"Main"方法

C:\Projects\Some\src\Some.Core\error CS5001: Program does not contain a static 'Main' method suitable for an entry point

我假设整个解决方案应该只有一个Program.cs/入口点,并且它位于我的WebApi项目内部.我说错了吗?否则,如何解决此错误?我错误地认为"emitEntryPoint": true可达到此目的.

I am assuming that there should be only one Program.cs / entry point for the overall solution, and that is sitting inside of my WebApi project. Am I incorrect? Otherwise, how do I resolve this error? I falsely assumed that "emitEntryPoint": true served this purpose.

这是我的类库的project.json的示例:

Here is an example of my class library's project.json:

{
  "version": "1.0.0-*",
  "description": "Some.Core Class Library",
  "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Routing": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.Identity": "1.0.0",
    "Microsoft.Extensions.Configuration": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
  },

  "frameworks": {
    "netstandard1.6": {
      "dependencies": {
        "NETStandard.Library": "1.6.0"
      }
    }
  },
  "runtimes": {
    "win7-x64": {}
  }
}

建议表示赞赏.

推荐答案

要避免在类库中出现程序不包含适用于入口点的静态'Main'方法"的错误,请从buildOptions-中删除generateEntryPoint-

To avoid the error of "Program does not contain a static 'Main' method suitable for an entry point" in class library, Remove emitEntryPoint from buildOptions-

  "buildOptions": {
    "emitEntryPoint": true
  },

emitEntryPoint告诉编译器是创建控制台应用程序还是库.有关更多信息,请参见此帖子

emitEntryPoint tells the compiler whether to create a Console Application or a Library. For more info refer this post

这篇关于Asp.Net Core:程序不包含适用于入口点的静态"Main"方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆