NET 10 might help: New in the .NET 10 SDK: Execute a .cs file
dotnet run file.cs
https://github.com/dotnet/sdk/blob/main/documentation/general/dotnet-run-file.md