首页 > 其他分享 >dotnet build error CS5001: Program does not contain a static 'Main' method suitable for an

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

时间:2022-08-14 22:13:46浏览次数:102  
标签:Main point does Program static build contain suitable

前言

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! 不同平台下做了兼容

标签:Main,point,does,Program,static,build,contain,suitable
From: https://www.cnblogs.com/lic0914/p/16586513.html

相关文章