Asp.Net Core:程序不包含适用于入口点的静态"Main"方法

编程入门 行业动态 更新时间:2024-10-28 17:16:57
本文介绍了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"方法

本文发布于:2023-11-15 12:38:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1594517.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:适用于   静态   不包含   入口   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!