Skip to content

Cannot publish a project with top-level statements if an output directory is specified #55295

Closed

Description

@TheLeftExit

Describe the bug

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+f7b4c5716

Runtime 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:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

IDE version

No response

Other details

No response

Activity

  1. added
    untriaged
    on Jul 15, 2026
  2. Pixel-Tony commented on Jul 18, 2026

    @Pixel-Tony

    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

  3. TheLeftExit commented on Jul 18, 2026

    @TheLeftExit
    Author

    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.

  4. jjonescz commented on Jul 20, 2026

    @jjonescz
    Member

    Looks very similar to #53626 although I would expect that to be already fixed in .NET 11

  5. TheLeftExit commented on Jul 22, 2026

    @TheLeftExit
    Author

    Still reproducible with 11.0.100-preview.6.26359.118

  6. removed
    untriaged
    on Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions