C# is my second-favorite language. I made a shebang to do the same for rust (my number one) many years ago with zero (external) dependencies: https://neosmart.net/blog/self-compiling-rust-code/
//usr/bin/env rustc "$0" && ./config "$@"; exit
Or //usr/bin/env rustc --edition 2024 "$0" && ./$(basename $0 .rs); rm $(basename $0 .rs); exitShell scripts are ugly :)
(If you didn't mean to use them in a shebang but rather as the script body, that's fine but that wouldn't be possible without the polyglot syntax and #allow abuse I posted.)
I would have liked to use `exec -a` to set the executable name (as mentioned in the comments on the article) but alas, that too is not portable.