News for hackers. Stuff that matters.
Re:dotnet run app.cs by andix on Thursday May 29, 2025 @02:55PM (#44129047)
This 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>"

Re:dotnet run app.cs by smarx007 on Thursday May 29, 2025 @03:58PM (#44129706)
> 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 without any issues. Skipping an extra step would be cool though.

Re:dotnet run app.cs by andix on Thursday May 29, 2025 @04:31PM (#44130080)
Is it possible to add those scripts project-scoped like with npm run? They should work for everyone who checks out the repo.
Re:dotnet run app.cs by smarx007 on Thursday May 29, 2025 @04:36PM (#44130131)
I 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-d... which I absolutely love.

Re:dotnet run app.cs by bladeee on Thursday May 29, 2025 @05:16PM (#44130468)
You can use project-scoped tool manifests. Then you can call dotnet tool restore to load all tools specified in the manifest.

https://learn.microsoft.com/en-us/dotnet/core/tools/global-t...

Re:dotnet run app.cs by smarx007 on Thursday May 29, 2025 @05:19PM (#44130492)
TIL, thank you!
Re:dotnet run app.cs by andix on Saturday May 31, 2025 @02:36PM (#44146147)
Sure, but I think you still need to provide the full path of the script. If you're inside a source folder very deep it will lead to something like:

  dotnet script ../../../../../scrips/scaffold-something.cs
With npm run it works from any subdirectory:

  npm run scaffold-something
Re:dotnet run app.cs by Inception on Thursday May 29, 2025 @04:01PM (#44129734)
This would be great! I'm currently using make files to accomplish this: https://www.gnu.org/software/make/
Re:dotnet run app.cs by andix on Saturday May 31, 2025 @02:39PM (#44146158)
How can you use make as a script runner? Is it possible to add targets that are not part of the tree and execute every time you run them?

something like

  make clear-test-database
that runs every time you execute it, but is not executed on make all or make clean?
Re:dotnet run app.cs by ryanbuening on Thursday May 29, 2025 @03:54PM (#44129667)
Re:dotnet run app.cs by tylerflick on Thursday May 29, 2025 @03:06PM (#44129152)
I remember using LINQPad when I needed this functionality filled.
Re:dotnet run app.cs by mystified5016 on Thursday May 29, 2025 @04:42PM (#44130195)
Nah, we've been doing this for years. At least ten years ago I built myself a little console based on Roslyn that would evaluate any C# snippets I gave it. C# scripts were pretty well supported, and it was not hard to throw one together. The engine of my console was a couple dozen lines mostly just processing the string.

I'm sure the tooling is better now, though. I seem to recall visual studio and/or Rider also supporting something like this natively at the time.

Re:dotnet run app.cs by notnmeyer on Thursday May 29, 2025 @07:30PM (#44131384)
you’re better off using a separate task runner like make or task.
Re:dotnet run app.cs by andix on Thursday May 29, 2025 @09:09PM (#44131856)
I don't think make and task are suited very well for running scripts that are not part of the build process. Something like scaffolding, or starting a dev dependency. Also it requires the developers to install additional tools to get started with the project.