dotnet build error CS5001: Program does not contain a static 'Main' method suitable for an entry point

前言

Docker环境编译.Net6项目,出现诡异的CS5001

Program does not contain a static 'Main' method suitable for an entry point

image

排查

从报错信息看是Program.cs Main 方法找不到查看后没什么问题,都是默认的创建的看来不是这里的问题

经过一番Google后找到这个
https://stackoverflow.com/questions/9607702/does-not-contain-a-static-main-method-suitable-for-an-entry-point

解决

那就再.csproj 里添加

<OutputType >Library</OutputType>

确实有用 build成功了
但这有点问题啊 在win环境下运行报错了,没错你的OutputType不正确,要使用Exe才行,这就需要条件编译了,方法如下:

1.Dockerfile build时添加-r linux-x64

dotnet build xx.csproj -c Release -o /app/build -r linux-x64

2.在csproj里添加

<OutputType Condition="$(RuntimeIdentifier.StartsWith('linux'))">Library</OutputType>

OK! 不同平台下做了兼容

posted @   流年灬似氺  阅读(850)  评论(2编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示