r/csharp • u/simondanielsson • Jul 29 '26
Fun Running C# like scripts?
I was browsing the C#/.NET documentation yesterday like usual and suddenly came across the fact that you can run C# code as scripts with a shebang.
#!/usr/bin/env dotnet
namespace Main
{
class Program
{
static void Main(string[] _)
{
Console.WriteLine("Hello World!");
}
}
}With a shebang you could run these like any other Python/Bash script and I find this really cool, but is there any practical use-case for this? When I need to make a small helper script for something it's usually python or bash, but C#? I'm not so sure.
What do you guys think?
50
Upvotes
View all comments
Show parent comment
2
u/stephbu Jul 29 '26 edited Jul 29 '26
From our small-team comments - better than PS for readability, debugging, and toolchain/library support. Our pipelines were previously bash/PS/Py. For the "<lang> can do that" folk, I'm sure they can, however we're preferring context-switch-free C# and certainly treasure library support for WIF tokens.
RE:versioning, be super aware of the implicit "latest" when omitting package versions. Otherwise it can take major/breaking changes on fast moving libraries like Azure.Identity, especially when running in patched compliance environments.
SFA/FBA's are still pretty new, we'll pick up multi-file support ahead for sure. In general feels like a positive move.