Skip to content

#! "shebang" directives have changed from disallowed to allowed in ordinary files in recent compilers #78301

Open
@RikkiGibson

Description

@RikkiGibson

Repro:

  • install .NET 10 preview SDK
  • Shell:
$ dotnet new console -f net9.0 -o MyApp
$ cd MyApp
$ dotnet new globaljson
  • Insert #!something at top of file
  • dotnet build

Expected result: Program.cs(1,1): error CS1024: Preprocessor directive expected
Actual result: Build succeeded

If you edit the global.json to use .NET 9 SDK and build again, the expected error occurs.

In the ignored directives design we decided to block #: in the context of ordinary projects. It's not obvious to me if we decided to lift the pre-existing restriction on #! in ordinary projects. I expected the design to align, where in .cs files, either both #! and #: are permitted, or both are disallowed.

It's quite possible we discussed and accepted the behavior described in this bug, in which case please link it and close out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilersFeature - Ignored Directives#: and #! directives in file-based C# programsuntriagedIssues and PRs which have not yet been triaged by a lead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions