13 ms·
Run a C# file directly using dotnet run app.cs
- adzm 1y agoFinally! Perfect for making a quick utility to use in a script. There have been third party solutions but having to install something to do this was always another obstacle / headache
- motorest 1y agoI feel like top level statements were created specifically to open the door to C# scripts. The syntactic sugar of top level statements doesn't make sense in regular .NET production apps that you need to build and run, but for quick scripts they do represent important improvements in DX. Well done.
- oaiey 1y agoTheir argumentation for both is accessibility for learning environments. Python and node were eating the cake there with ease of first use (python file.py). And what the academia is using today's is next year's company language
- pjmlp 1y agoAs someone mostly focused on JVM, .NET and nodejs ecosystems, this won't cut it. The problem with UNIX culture shops not picking up .NET has everything to do with the Microsoft stigma, and everything the management keeps doing against .NET team efforts, like VSCode vs VS tooling features, C# DevKit license, what frameworks get to be on GNU/Linux, and the current ongoing issues with FOSS on .NET and the role of .NET Foundation. Minimal APIs and now scripting, which already existed as third party solutions (search for csx), won't sort out those issues. They can even start by going into Azure and check why there are so many projects now chosing other languages instead of .NET, when working on the open. This would already be the first place to promote .NET adoption.
- tester756 1y ago>UNIX culture shops Jesus christ, it sounds like a religion
- pjmlp 1y agoWelcome to technology flamewars. The only change through the times is where they take place and how hard, or low, they might get.
- HideousKojima 1y agoI mean I don't want the viability of my business to be dependent on the whims of Microsoft either. Unfortunately your business is going to have counterparty risk no matter what your tech stack is but Microsoft's record is pretty mixed.
- GoblinSlayer 1y agoAFAIK, you could always dotnet run app/app.csproj since 2016. Obviously you needed dotnet sdk installed.
- Digit-Al 1y agoYes, but this change now also allows you to do the same with, say, script.cs file.
- Incipient 1y agoInstalling the full dotnet sdk was very high friction, in addition to the full csproj scaffolding. Running a single cs file is a HUGE ux improvement. If python hadn't (nearly) caught up to c# in typing support, I'd seriously consider moving or at least running it...but as it stands, python has established itself too well for me.
- motorest 1y ago> Installing the full dotnet sdk was very high friction, in addition to the full csproj scaffolding. What's the difference between installing .NET or, say, python of node?
- noworriesnate 1y agoPython typing hasn’t nearly caught up with C#. I regularly use both and c#’s type system is pragmatic and very helpful in avoiding bugs, whereas Python has no types by default and doesn’t check them by default when it does have them. It’s worse than typescript because at least typescript fails to compile if you have a type error.
- GoblinSlayer 1y agoYou still need full dotnet sdk, the tool merely automates full csproj scaffolding, which is then compiled with full dotnet sdk, roslyn, nuget, compiler server and everything, and allows to customize msbuild project properties with pragmas in code. The only difference is that before you had sdk+folder+my.cs+my.csproj, now you have sdk+folder+my.cs
- necovek 1y agoAny number of these small papercut-like things is what has made a tool like Python ubiquitous.
- 01HNNWZ0MV43FF 1y agoWith `uv` you can even put a magic comment atop the script saying like, "Use this version of Python, use these dependencies" and uv will fault the runtime and deps into a cache folder before launching the script. 2025 might be the year of Python on the desktop
- unitexe 1y ago[dead]
- linkage 1y agoWhen Astral ships the ability to package your Python script + its dependencies in a single, statically linked executable, it's game over for everyone else.
- exceptione 1y agoBut don't tell the people they could have that right now, but performant and type safe.
- throwaway889900 1y agoHaving the thing is better than not having the thing, even if it's not the best version of the thing.
- exceptione 1y agoYes, but it is not without cost. The time poured on all the failed projects to make Python into what it fundamentally isn't is quite wasteful in my opinion. But people are free to do whatever they want with their own time.
- CommonGuy 1y agothis will make scripting with C# so much easier
- rjbwork 1y agoVery cool. Will probably still stick with LINQPad for my every day experimentation needs but if i decide to write actual scripts for ~production use, this would be a better alternative to Powershell in most cases I think.
- pragmatic 1y agoSeems like a great PowerShell replacement. PowerShell is the ultimate Chatgpt language. For better or worse. Usually worse as most shops end up with "write only" PowerShell scripts running all the glue/infrastructure stuff.
- motorest 1y ago> Seems like a great PowerShell replacement. It sounds like it can potentially replace way more than PowerShell. I mean, why would a .NET shop even bother with Python or any form of shell scripts if they can attach a shebang on top of an ad-hoc snippet? And does anyone need to crank out express.js for a test service if they can simply put together a ASP.NET minimal API in a script?
- pjmlp 1y agoEcosystem, people keep forgetting syntax, grammar and standard library isn't everything. That is why even the languages I dislike and am not a big fan of, have a little place on my toolbox.
- motorest 1y ago> Ecosystem, people keep forgetting syntax, grammar and standard library isn't everything. Ecosystem means nothing if you have comparable or even better alternatives in a framework of choice. Also, it's not like the likes of Python don't have their warts. Anyone with a cursory experience with Python is aware of all the multiplatform gotchas it has with basic things like file handing.
- mattmanser 1y agoFor me, every time I have to use python it's the package handling that leaves my head spinning. It still feels like the bad old days of npm. I think it's a popular language with scientists despite that because they don't have to care about portability, reproducability or needing your replacement to be able to run it without ever speaking to you. I use python infrequently enough that every time it's a pain point.
- jiggawatts 1y agoThere's a rule that if something is easy to invent, a bunch of people will whip up their own versions independently, sometimes even within the same organisation. So for there's... C# scripting (CSI.exe): https://learn.microsoft.com/en-us/archive/msdn-magazine/2016/january/essential-net-csharp-scripting https://learn.microsoft.com/en-us/archive/msdn-magazine/2016... PowerShell Add-Type that allows one-file inline C# scripting: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/add-type?view=powershell-7.5#example-1-add-a-net-type-to-a-session https://learn.microsoft.com/en-us/powershell/module/microsof... The Roslyn .CSX script files (RCSI.exe): https://devblogs.microsoft.com/visualstudio/introducing-the-microsoft-roslyn-ctp/ https://devblogs.microsoft.com/visualstudio/introducing-the-... .NET Interactive: https://github.com/dotnet/interactive https://github.com/dotnet/interactive ... and now this.
- coolgoose 1y agoReading all the above, this is nothing like that. It's just standard c# no new dialect, works like a proper 'shell' script and it's not a repl, what am I missing
- oaiey 1y ago.net interactive is a kernel based approach for notebooks. CSI is more like a traditional repl (extracted from a VS feature). This here is more like traditional scripting. It is coding without project file. There is no attempt of interactivity here.
- motorest 1y ago> There's a rule that if something is easy to invent, (...) You seem to be confused. There is nothing being invented in here. What they are announcing is basically an update to the dotnet command line app to support building and running plain vanilla C# programs.
- pjmlp 1y agoIndeed, what I find somehow dishonest is the lack of acknowledgement of previous efforts. The whole presentation at BUILD was done as if it was a great ideas, they only thought about it now.
- revskill 1y ago.csproject and visual studio is the main reason i avoid csharp. The whole setup feels dumb for no reason.
- oaiey 1y agoWhy dumb? Sure there is 1-2 syntax warts left, but the files are very expressive nowadays.
- knallfrosch 1y agoDeciding whether something is netFramework 4.8 or .NET Core 5 or NET3000 or nEt5 or NET Common 2.0 is impossible. Isn't that one of the most basic things that should be easy. Half of the properties are XML attributes <tag ID=5> while the other half are child tags <tag><hello>5</hello></tag> It's okay to read, but basically impossible to write by hand. The tooling support is nothing like a JSON with JSON schema that gives you full intellisense with property autocomplete plus attribute description. (Imagine VSCode settings)
- motorest 1y ago> Deciding whether something is netFramework 4.8 or .NET Core 5 or NET3000 or nEt5 or NET Common 2.0 is impossible. Is it, though? The guidelines seem to be pretty straight forward: unless you want to target a new language feature, you can just target netstandard or whatever target framework your code requires at the moment. This barely registers as a concern. https://learn.microsoft.com/en-us/dotnet/standard/net-standard https://learn.microsoft.com/en-us/dotnet/standard/net-standa... > It's okay to read, but basically impossible to write by hand. Are you sure about that? I mean, what's the best example you can come up with? This complain is even more baffling considering a) the amount of XML editor helpers out there, b) the fact that most mainstream build systems out there are already XML-based.
- WorldMaker 1y agoI personally wouldn't bother with .NET Standard anymore. .NET Standard 2.0 is nicely frozen and still useful to some legacy shops, but at this point I think for all new code the only decision is to support LTS or not, and then just pick the latest version.
- mhh__ 1y agoMaybe one day they'll bite the bullet and let you write a function without extra 10 keywords and a sprinkling of nouns I really want to like C# but there is a reason why it has no ecosystem outside of enterprise and gaming slop
- oaiey 1y agoWhich 10 extra key word? It is a statically typed (bring things like types, type parameters, ...), object oriented language (brings things like abstract, override, class, ...) and high performance (brings things like ref, in, out, ...). And it is expressive instead of "mathematical" (like ML languages) which makes productively in code reviews a thing. It is exactly where it should be.
- motorest 1y ago> Maybe one day they'll bite the bullet and let you write a function without extra 10 keywords and a sprinkling of nouns I have no idea what you are talking about. Care to present a single example?
- mhh__ 1y agowell to do anything new in a C# project one typically ends up making a class inside a new namespace, if I just want to write a solver with no state it's quite jarring and distracts from otherwise a pretty good language that I like working in. So 2 new nouns and a handful of keywords.
- motorest 1y ago> well to do anything new in a C# project one typically ends up making a class inside a new namespace (...) You don't need to. A few years ago, C# introduced top-level statements. They were introduced in 2020, I think. https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/program-structure/top-level-statements https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals...
- voidUpdate 1y agoA namespace isn't required
- adzm 1y agoThere is even more info in the proposal itself https://github.com/dotnet/sdk/blob/main/documentation/general/dotnet-run-file.md https://github.com/dotnet/sdk/blob/main/documentation/genera... specifically things about multiple files and more specifics of the implementation and capabilities (implicit project file etc)
- tgma 1y agoDidn't Mono implement something like this ages ago? And I mean ages ago, before C# even had standardized code outside "static void Main" in the language spec, IIRC they had an interpreter that probably used Reflection.Emit or something and executed the output and you could #! it.
- mrcsharp 1y agoI'm excited for this one. I can see it replacing some of the powershell scripts I have in CI/CD pipelines. As much as I like Powershell and Bash, there are some tasks that my brain is wired to solve more efficiently with a C-like syntax language and this fill that gap for me.
- GoblinSlayer 1y ago>Because of the implicit project file, other files in the target directory or its subdirectories are included in the compilation. Errm, so how is this different from a folder with a project file?
- zigzag312 1y agoProbably, you can have multiple scripts in one folder. Eg script1.cs, script2.cs...
- GoblinSlayer 1y agoThat's it, and they are all compiled into one executable as implicit items, and everything in subfolders.
- motorest 1y ago> Errm, so how is this different from a folder with a project file? It requires neither a folder nor a project file. Just pass the source file as the argument and you have everything up and running.
- GoblinSlayer 1y agoIf you don't put it in a folder, then entire folder tree is compiled into your script.
- recursive 1y agoThat doesn't seem true based on the introduction. Where are you seeing that info?
- GoblinSlayer 1y agoIn the end the post links to spec. >By default, file-based apps use the Microsoft.NET.Sdk SDK. This behavior is default provided by sdk to keep project files small.
- occz 1y agoThis also exists for Kotlin: https://github.com/Kotlin/kotlin-script-examples/blob/master/jvm/main-kts/MainKts.md https://github.com/Kotlin/kotlin-script-examples/blob/master... (note that the file extension is load bearing in this case, if you don't name it "*.main.kts", it will not work). It's excellent for writing small scripts/prototyping where you need access to some Kotlin/JVM feature. Ruby is still my preferred language for small scripts though - the backticks for running external programs is remarkably ergonomic
- bitwize 1y agoI think it also exists for Java itself now.
- vips7L 1y agoYes. You can just run java myfile.java
- carstenhag 1y agoIt's not going away entirely, but its future is also not so shiny: https://blog.jetbrains.com/kotlin/2024/11/state-of-kotlin-scripting-2024/ https://blog.jetbrains.com/kotlin/2024/11/state-of-kotlin-sc...
- moogly 1y agoKind of obsoletes NetPad, and as soon as there's debugging, LINQPad can be put out to pasture. LINQPad was instrumental for me many years ago, and I appreciate that, but that stone-age text editor is not usable for actually writing/editing code in this decade.
- pjmlp 1y agoOnly if they do all GUI features and extension points, which I doubt pretty much.
- moogly 1y agoThere's very useful stuff there for sure, just gated behind an unfathomably deficient code editor. IMO Albahari should just embed Monaco in it.
- Salgat 1y agoLooks like they will be adding support for VS Code, including for debugging. "In upcoming .NET 10 previews we’re aiming to improve the experience of working with file-based apps in VS Code, with enhnanced IntelliSense for the new file-based directives, improved performance, and support for debugging."
- pjmlp 1y agoStill, it isn't like graphically dump a data structure like in LinQPad.
- pletnes 1y agoLinqpad is super cool in certain .net ways, but oh man the text editor component is the worst one I interact with on a regular basis. I wish that part would be replaced by neovim or monoaco or, basically, anything. The snappiness, the table visualizations and so forth - very nice. It’s also been unable to keep up with notebook tech for many potential use cases. I guess it’s a one man show and it shows. Still, massive hat tip - I use Linqpad every day because it’s super useful for playing with your SQL data.
- 1y ago
- throwaway896987 1y agoThe oldest one: https://github.com/oleg-shilo/cs-script https://github.com/oleg-shilo/cs-script Used it 10+ years in production, but usually no one I talk to in .net world has ever heard about it.
- jarym 1y agoI used this MANY years ago for a reporting system for a French supermarket chain. Their developers were really pleased with it!
- GoblinSlayer 1y agoI heard about alintex script http://web.archive.org/web/20051104042052/http://www.alintex.com/products.aspx http://web.archive.org/web/20051104042052/http://www.alintex...
- jbverschoor 1y agoGreat, but unfortunately, even when compiled, the startup overhead is about half a second, which makes it unsuitable for many applications. Still I applaud it, as Shell scripting is finicky, people thend to rely on bash features, and perl is kind of over. Ruby was, and still is, my go-to language for this purpose, but I've recently migrated some scripts over to Swift. Swift does a much better job at this as interprets by default, and a compiled version starts instantaneously. I made a transparent caching layer for your Swift cli apps.Result: instant native tools in one of the best languages out there. Swift Script Caching Compiler (https://github.com/jrz/tools https://github.com/jrz/tools) dotnet run doesn't need it, as it already caches the compiled version (you can disable with --no-build or inspect the binaries with --artifacts-path)
- alkonaut 1y agoDoes this recompile each time? It should be simple to cache the binary on the hash of the input? A sub second first run followed by instant rerun seems acceptable.
- wiso 1y agoBinaries are cached and next runs are much faster
- jbverschoor 1y agoThe dotnet run command caches. However, even with the cached version, you have a startup overhead of about half a second on my M1. My "Swift Script Caching Compiler" compiles and caches, but will stay in interpreted mode the first three runs when you're in an interactive terminal. This allows for a faster dev-run cycle.
- motorest 1y ago> Great, but unfortunately, even when compiled, the startup overhead is about half a second, which makes it unsuitable for many applications. Which applications are those? I mean, one example they showcase is launching a basic web service.
- pjmlp 1y agoI find it a pity the lack of acknowledgement of the CSX/VBX effort. https://ttu.github.io/dotnet-script/ https://ttu.github.io/dotnet-script/ Or that they on the wisdom of the C# Language Runtime, decided on an incompatible approach to how F# references dependencies on its scripts. https://learn.microsoft.com/en-us/dotnet/fsharp/tools/fsharp-interactive/ https://learn.microsoft.com/en-us/dotnet/fsharp/tools/fsharp...
- janjones 1y agoWhat do you mean by incompatible? If you mean syntax, that's different intentionally for clarity and also we don't want to create a new C# scripting dialect hence it isn't possible to "import" other files (that's not how C# works).
- pjmlp 1y agoThe # declarations syntax for Assembly references.
- janjones 1y agoAssembly references are not really a mainline scenario, hence we support nuget package references only for now. And `#r` is just too opaque (it comes from old times when assembly references were the norm).
- pjmlp 1y agoI disagree, this is the kind of decisions that make CLR the C# Language Runtime, instead of its original purpose, where there was an ecosystem of common approaches. Unless you plan to also support the same approach on VB and F# scripts.
- janjones 1y agoF# and C# are intentionally different languages, I don't think it makes sense to have 100% equivalent functionality in both. AFAIK, F# already has scripting functionality built in. VB support could be added, but that seems unlikely given https://learn.microsoft.com/en-us/dotnet/fundamentals/languages https://learn.microsoft.com/en-us/dotnet/fundamentals/langua...
- wiso 1y agoYou can also use shebang to run C# scripts like bash scripts https://devblogs.microsoft.com/dotnet/announcing-dotnet-run-app/#using-shebang-lines-for-shell-scripts https://devblogs.microsoft.com/dotnet/announcing-dotnet-run-...
- max23_ 1y agoI couldn't get the shebang to work by running the file directly with .net10 preview 4 sdk image. It works if I run `dotnet run <file>`. Update: It is working now, the file was using CRLF instead of LF.
- bouke 1y agoThat's great; now I can finally have scripts with type-safety. Note that on macOS the shebang either reads `#!/usr/local/share/dotnet/dotnet run` or `#!/usr/bin/env -S dotnet run`.
- thom 1y agoI 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?
- jiggawatts 1y agoThe 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.
- Kuinox 1y agoThis come from C++ preprocessor directive, and have been here since the first version of C#.
- noworriesnate 1y agoBeing able to use a shebang as a preprocessing directive is really creative. I’m really glad c# isn’t design-by-committee language.
- GoblinSlayer 1y agoWell, shebang is a comment.
- homebrewer 1y agoThose are not comments: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives 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.
- high_na_euv 1y agoSeems like a great Python replacement.
- davidgl 1y agoAnd F# which is more pythonlike already supports this via dotnet fsi - see https://learn.microsoft.com/en-us/dotnet/fsharp/tools/fsharp-interactive/#scripting-with-f https://learn.microsoft.com/en-us/dotnet/fsharp/tools/fsharp...
- zeroq 1y agoSome 20y ago I used "scratchpad" or whatever it was called to write short "bash" scripts and run them directly from that "notepad"... and it was a blast. I never understood why it has to be so hard on Windows to enable users to do just a little bit of scripting like it's not 80's anymore.
- pacoWebConsult 1y agoLINQPad [1] is a terrific utility for this workflow with dotnet. I was part of a team where we built all kinds of runbooks, support utilities, and debugging tools with LINQPad using a common set of utility functions to dump (pretty-print) system-specific entities and even charts. [1]: https://www.linqpad.net/ https://www.linqpad.net/
- endemic 1y agoI thought it was Windows only, but looks like there's a macOS version now!
- naikrovek 1y agoI can’t believe it took this long. It is insane to me how long it takes people to realize that low barriers for execution and experimentation are important. Imagine if the Commodore 64 or Microsoft Basic required you to scaffold your program with helper files containing very specific and correct information in order to run those programs.
- donatj 1y agoIt's interesting that they're actively promoting using it with a shebang. I find it pretty appealing. Go prior to modules worked really well this way and I believe Ubuntu was using it like this, but the Go authors came out against using it as a scripting language like this.
- flmontpetit 1y agoI used to work for a .NET shop that randomly wrote some automation scripts in bash. The expertise to maintain them long term (and frankly, write them half-decently to begin with) simply wasn't there. Never understood why they didn't just write their tooling in C#. Maybe this will make it seem like a more viable approach.
- psyclobe 1y agoBash is the tool that’s already there; that is always a real good reason to use it. Dotnet is a pig with its dependencies by comparison.
- dragonwriter 1y ago> Bash is the tool that’s already there; that is always a real good reason to use it. If you are a dotnet dev shop, it is quite likely that dotnet is also a tool that is already there the places you need automation. Plus, its also the tool that is already there in your team’s skillset.
- senthil_rajasek 1y agoI am an old hat. I've been in dotnet dev land for decades and still use bash (git bash). Pros: Syntax + access to familiar shell commands Cons: Bash scripts are not easy to maintain.
- gofreddygo 1y agoNot an old hat. in the dotnet world for 3 years, bash over a decade. Agree with bash not being easy to maintain. Argument about bash being always there breaks down quickly. Even if you limit yourself to bash+awk+grep, they dont work consistently across different bash flavors or across platforms (mac/win/linuz). My approach now is to have my programs, in the language most convenient to me, compiled to a bunch of archs and have that run across systems. One time pain, reduces over time.
- theanonymousone 1y agoAs nobody mentioned before, Java has had JBang for a while now: https://www.jbang.dev/ https://www.jbang.dev/
- resoluteteeth 1y agoI guess this continues the trend of c# eventually getting all the features from f#
- debugnik 1y agoAnd the trend of doing so in an incompatible way. .NET Interactive had already added a directive for C# NuGet references, compatible with F#'s, and NuGet's picker had already labeled that syntax "Script & Interactive". But no, they had to invent a new directive.
- sirjaz 1y agoIt seems Microsoft is trying to make C# more flexible and attractive to Data Scientists and beginners. They should have done this years ago.
- gwervc 1y agoThey indeed started years ago. For some time it's possible to run project with a Program.cs file that doesn't contain a static class. There's also the so called the ASP.NET minimal API. And .net scripting got official support a few releases ago.
- emursebrian 1y agoI've been developing with .NET since version 1.1. I feel like it's always been pretty easy to use for beginners. You install Visual Studio, create a new project and BOOM you've got a program that builds and runs. Having used Turbo Pascal and Turbo C prior to Visual Basic and Visual C, Microsoft's "Visual" IDEs and other Windows based IDEs of the 90's were a step up in ease of use even if they did require more files to build a project.
- ThinkBeat 1y agoAnnouncing proudly that botnet can now compile without a csproj file seems a bit over excited. It his basically: gcc test.c -o test.exe test.exe. and #!/ comple and run gcc test.c -o test.exe test.exe.
- high_na_euv 1y agoOn the contrary if cpp had something like csproj and it'd package manager by *default*, then it be 5 times less painful to use
- ozim 1y agoYou know that 99% of use are not botnets. Sounds like argument for not sharpening knives because criminals can stab people.
- knome 1y agoI think it's reasonable to assume the poster meant "dotnet" and that you're responding to a typo
- ComputerGuru 1y agoC# 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/ https://neosmart.net/blog/self-compiling-rust-code/
- higherhalf 1y agoSeems a little complicated when you can do: //usr/bin/env rustc "$0" && ./config "$@"; exit Or //usr/bin/env rustc --edition 2024 "$0" && ./$(basename $0 .rs); rm $(basename $0 .rs); exit
- ComputerGuru 1y ago&& in a shebang isn't portable, having more than one argument in a shebang isn't portable, subshell in a shebang isn't portable, semicolon in a shebang isn't portable, basename usage isn't portable, not littering the current working directory is important (it might not even be RW, or you might not have permissions to write to it), your usage won't work with symlinks or with the script added to $PATH, caching the compiled output is a nice speedup and reduces startup costs, correct (and optimal) cache invalidation is one of the known tricky problems in CS. Shell 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.)
- higherhalf 1y agoThanks, I looked it up and it's indeed quite ugly, and my shebang isn't portable. A little saddened that even 'env -S' didn't make it to POSIX.
- ComputerGuru 1y agoNo worries and believe me, I feel your pain (I moonlight as a (fish-)shell dev). 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.
- xunil2ycom 1y agoI've been coding in C# for more than a decade and a half now, and I see myself using this rather than creating an entire project structure to test some new approach to something.
- 90s_dev 1y agoWith Java allowing void main() {} like C, and now shebang C# scripts, is everything converging into one meta language?
- 90s_dev 1y agoGive me some sane subset of TypeScript with native support and I'll use it everywhere. But C# is far from as convenient as TypeScript so far. Just a few more years of convenience language features and APIs added, and I think it'll be set.
- devjab 1y agoInterpreted general purpose languages have been fairly similar for a while. I worked with C# for a decade, Go replaced it for us (for human reasons not technical ones) but these days everything is basically Python and then some C/Zig for parts that require efficiency.
- Zambyte 1y agoEvery subset of Lisp is growing into a full Lisp :)
- TowerTall 1y agoi couldn't help noticing that none of the autocomplete suggestions in his terminal or VS Code were relevant or correct. It looked really annoying. Is that the usual quality Copilot delivers?
- stackskipton 1y agoIt's slightly better for established code but it's like all of them. If it's well-known problem, it's decent. If it's esoteric or unique to your business, it's confused. Since C# single file is new, there is not a ton of code for Copilot to reference so it's probably confused.
- nayuki 1y agoJava SE 11 (Sep 2018) introduced the ability to run source files directly. So instead of the old `javac Main.java && java Main`, you can do `java Main.java`. https://openjdk.org/projects/jdk/11/ https://openjdk.org/projects/jdk/11/ , https://openjdk.org/jeps/330 https://openjdk.org/jeps/330
- rpozarickij 1y agoFurthermore, there's ongoing work ([0] and related JEPs) to allow running single Java files without an enclosing class and the static main method: void main() { System.out.println("Hello, World!"); } This is currently (as of JDK 24) under preview, so such a file needs to be run with "--enable-preview". E.g. $ java --enable-preview HelloWorld.java Hello, World! [0] https://openjdk.org/jeps/445 https://openjdk.org/jeps/445
- msgilligan 1y agoWith the latest EA release (EA 24) of JDK 25 [1], you no longer need the `--enable-preview`. You can also simplify the println to: void main() { IO.println("Hello, World!"); } JEP 445 has been followed by JEP 512 which contained minor improvements and finalizes the feature [2]. If you want to use 3rd-party libraries, I highly recommend trying JBang [3]. [1] https://jdk.java.net/25/release-notes https://jdk.java.net/25/release-notes [2] https://openjdk.org/jeps/512 https://openjdk.org/jeps/512 [3] https://www.jbang.dev https://www.jbang.dev
- ptx 1y agoHmmm... Disappointing that the static methods are no longer imported as of JEP 512. I thought that was the whole point of the new IO class. If we can't write "println" we might as well just write "System.out.println".
- renatovico 1y agovery cool, but only one thing come in mind, the new .VBS !
- andix 1y agoThis feature is probably a big thing for .NET developer productivity. It's quite a shame, that it only came now. There is another thing I'm really missing for .NET projects. The possibility to easily define project-specific commands. Something like "npm run <command>"
- tylerflick 1y agoI remember using LINQPad when I needed this functionality filled.
- ryanbuening 1y agoAre you talking about this?: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-run https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-r...
- smarx007 1y ago> This feature is probably a big thing for .NET developer productivity. It's quite a shame, that it only came now. I am using https://github.com/dotnet-script/dotnet-script https://github.com/dotnet-script/dotnet-script without any issues. Skipping an extra step would be cool though.
- andix 1y agoIs it possible to add those scripts project-scoped like with npm run? They should work for everyone who checks out the repo.
- smarx007 1y agoI think everyone needs to do `dotnet tool install -g dotnet-script` before running them. This is the most annoying part where .NET 10 announcement would be really appreciated. But then each script has an individual list of dependencies so there should be no need for further scoping like in npm (as in, the compilation of the script is always scoped behind the scenes). In this regard, both should be similar to https://docs.astral.sh/uv/guides/scripts/#declaring-script-dependencies https://docs.astral.sh/uv/guides/scripts/#declaring-script-d... which I absolutely love.
- DiabloD3 1y agoThis isn't a new feature, and was announced for... I think 8. Why is it being re-announced now?
- Salgat 1y agoMaybe you're confusing it with top-level statements? This new feature doesn't even require a csproj.
- DiabloD3 1y agoNo, I do absolutely remember them integrating dotnet-script-like functionality into the runtime, and I remember experimenting with it. Was it only in a beta version and removed to re-appear now? It used the Rosyln compiler to compile on demand and then execute it, and used pragma directives that were compatible with dotnet-script's. I cannot remember what the shebang was set to, but it wasn't the same one as dotnet-script.
- zerr 1y agoHow is it going with native AOT? I'd rather prefer: dotnetc app.cs ./app
- DMiradakis 1y agoI'm building a dotnet job orchestrator called Didact (https://www.didact.dev https://www.didact.dev), and this is the sort of thing I was looking for years ago when I was first dreaming it up. Class libraries is the approach I am taking now, but this is still extremely interesting. Could see some interesting use cases for this...
- arrty88 1y agoWould be cute to alias dnx to get ‘dnx app.cs’
- deleted 1y ago[deleted]
- replwoacause 1y agoAs someone just getting into C# from PowerShell, this is huge.
- WuxiFingerHold 1y ago>> Install Visual Studio Code (recommended) If you’re using Visual Studio Code, install the C# Dev Kit I wish Microsoft would just provide a LSP server for C#. Not just a half proprietary extension for VS Code.
- _betty_ 1y agowould they still be able to charge for it if it was an lsp?
- pipeline_peak 1y agoOn the topic of scripts, it would be nice if they had a more seamless way to invoke processes. The whole Process.Start() way can be convoluted when I just want something simple. Either way, this is a dream come true. I always hated Powershell and it’s strange fixation with OOP. Modern C# seems to acknowledge that sometimes all we want are functions, scripts, Linq and records.
- masfoobar 1y agoIts good to finally see this being 'a thing' in C#. In my opinion, it is 10 years overdue! This feature is likely added to compete with Python, Ruby, etc. The fact you just create a file, write some code and run it. However, I don't see C# being a competitor of said languages even for simple command lines. If anything, it could be a viable replacement to Powershell or maybe F# especially if you need to link it to other .NET DLLs and 'do things' I am also interested in the performance difference compared to other languages. I mean even Dlang has a script-like feature for sometime, now.. rdmd. Not sure the status of that, but it still compiled and runs the program. Just seems overkill for something rather simple.
- oaiey 1y agoThis is about education and mindset. Not to enter the space. There might be some people working with it, if they are more relaxed with C# than bash. Performance right now is horrible (500ms), they promised to improve it, but let us be honest: They are in-memory scaffolding a project, run msbuild restore/reassess/reuse dependencies, and then compile a dll and then load it into a JIT. that is so many more steps than a interpreter will do.
- masfoobar 1y ago> They are in-memory scaffolding a project... Absolutely...100% !!
- sahil_sharma0 1y ago[dead]
- deleted 1y ago[deleted]
- DeafMan1983 1y agoWhat is about NativeAot of Dotnet? If you run direct Dotnet App?