You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot publish a project with top-level statements if an output directory is specified #55295
I found this after I upgraded my project from .NET 10 to .NET 11, and dotnet publish <other parameters> -o ./ in my build script stopped working for it.
If there's a project that uses top-level statements, and you run dotnet publish -o ./ for it, the build fails with CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point.
Steps to reproduce
dotnet new console
dotnet publish -o ./
Expected behavior
The project publishes successfully.
Actual behavior
$ dotnet publish -o ./
Restore complete (0.2s)
info NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
NoMainTest net11.0 failed with 1 error(s) (0.2s)
CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point
Build failed with 1 error(s) in 0.5s
Is this a regression?
Yes, publishing this way worked in .NET 10.
Are there any workarounds?
N/A
dotnet --info output
.NET SDK: Version: 11.0.100-preview.5.26302.115 Commit: f7b4c5716f Workload version: 11.0.100-manifests.079a891b MSBuild version: 18.8.0-preview-26302-115+f7b4c5716Runtime Environment: OS Name: arch OS Version: OS Platform: Linux RID: linux-x64 Base Path: /usr/share/dotnet/sdk/11.0.100-preview.5.26302.115/.NET workloads installed:There are no installed workloads to display.Configured to use workload sets when installing new manifests.No workload sets are installed. Run "dotnet workload restore" to install a workload set.Host: Version: 11.0.0-preview.5.26302.115 Architecture: x64 Commit: f7b4c5716f.NET SDKs installed: 11.0.100-preview.5.26302.115 [/usr/share/dotnet/sdk].NET runtimes installed: Microsoft.NETCore.App 11.0.0-preview.5.26302.115 [/usr/share/dotnet/shared/Microsoft.NETCore.App]Other architectures found: NoneEnvironment variables: Not setglobal.json file: Not foundLearn more: https://aka.ms/dotnet/infoDownload .NET: https://aka.ms/dotnet/download
has had the same problem while running a publish inside a GitHub action, but after switching from 9.0 to 10.0. Fixed it by choosing another folder, not the one directly parenting the project source. The behavior is very strange, especially considering locally it still works fine, but fails when trying to publish in the runner
Yea, I tested this a bit more and it seems to not like the current directory (./) and paths containing a reference to a parent directory (../), while just plain directory names work. Might have something to do with that.
Activity
Pixel-Tony commentedon Jul 18, 2026
has had the same problem while running a
publishinside a GitHub action, but after switching from 9.0 to 10.0. Fixed it by choosing another folder, not the one directly parenting the project source. The behavior is very strange, especially considering locally it still works fine, but fails when trying topublishin the runnerTheLeftExit commentedon Jul 18, 2026
Yea, I tested this a bit more and it seems to not like the current directory (
./) and paths containing a reference to a parent directory (../), while just plain directory names work. Might have something to do with that.jjonescz commentedon Jul 20, 2026
Looks very similar to #53626 although I would expect that to be already fixed in .NET 11
TheLeftExit commentedon Jul 22, 2026
Still reproducible with
11.0.100-preview.6.26359.118