I know C# people like to think up three new forms of syntax before breakfast, but it feels like these magic comments could have been attributes?

Those are not comments:

https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...

They've been supported for decades at this point, they're not new. Your suggestion would require more changes to the language than what's actually implemented, afaiu.

Apologies, I left C# years ago when there were only 5,000 things to keep in your head at any one time.

I find it odd you feel that way.

I find C# to be remarkably better than javascript, for example, of having a 'right' way to do something.

Even when there are multiple ways the community tends to coalesce around one way.

C# always supported preprocessor directive.

Yes, but I would have thought attributes were the canonical "think you might want to reflect over" rather than this imperative solution. But you're all happy with it and it's not my circus, so enjoy.

This cannot be something you reflect over, because they allow to encode build arguments. They need to be parsed before it's compiled, which is exactly what preprocessors directive allows.

Java's annotations (which are mostly equivalent to C#'s attributes) can be consumed at compile time using annotation processors. If C# had this feature for attributes, could attributes have been used here?

C# have this feature, it's called roslyn code generator.

I believe your java annotations cannot change the build parameters of the package being currently compiled, which is why you wouldnt be able to do that in java.

btw, anything that is present in the AST could be used for that, but I think the preprocessor directive is the most sensible choice.

Fair enough. Presumably I can query a script first somehow to see what the dependency tree is going to look like?

Well for regular dotnet project there is `dotnet list` that allow that, I don't know how it will look c# script file, probably the same.

From what I've read of this preview `dotnet list` works as expected. Under the hood it supposedly builds a mini-project file so that most of the `dotnet` cli works as expected. It also provides an "eject button" to build the csproj from the script file `dotnet project convert`.

Yup; from v1

[deleted]

The motivation was almost certainly compatibility UNIX shebang lines for shell scripts:

    #!/usr/bin/dotnet run
    Console.WriteLine("Hello from a C# script!");
Which just looks like a crime against nature and right order of things.

It's really hard to explain to anyone who wasn't born in a monoculture, but I come from an eastern european country where in my childhood there may have been maybe a few hundred truly foreign people living there at any one time, mostly diplomats and their families. Decades later I visited and saw a chinese immigrant speaking my native tongue. You can't imagine how... disconcerting that is. Not bad, I'm not against it, it's just... weird.

This feels exactly like that.

This come from C++ preprocessor directive, and have been here since the first version of C#.

Being able to use a shebang as a preprocessing directive is really creative. I’m really glad c# isn’t design-by-committee language.

Well, shebang is a comment.