Open teo-tsirpanis opened 4 years ago
I'm trying on this project(https://github.com/WeihanLi/dotnet-exec) to execute code directly without a project file, it would be great and simple to run without a project file
I think this is closely related to the https://github.com/dotnet/fsharp/issues/13341 where people like to have FSX files to be compiled down to exe files. Currently dotnet SDK assumes that every executable target has project file, but for scripting environments that's not true. Great that some interest was shown in https://github.com/dotnet/designs/pull/213, but seems to be initiative to move this forward does not materialized yet
dotnet-repl which is based on dotnet-interactive achieves a similar thing, it also allows to execute C# and F# files.
When released, the .NET Core CLI tools made .NET development significantly easier with the command line. All it needs for a .NET Core app to run is a typically small
.*proj
file and the source files next to it.However, for very small programs (such as code for educational purposes or one-off scripts) whose project file is the same unremarkable one, it is a source of redundancy, especially when there are many source files on the same directory.
For this reason, and to emulate the behavior of tools like
python
andnode
with their respective languages, I am proposing to make commands likedotnet run MyFile.cs
compile and run a single-source-file app.This change will give a LINQPad-like feature to the .NET Core SDK and will make the .NET languages significantly more accessible and even enable them to be used like scripting languages.
Some other details I have thought:
* A command like
dotnet run MyFile.cs
will behave like creating a project file like this:and then running
dotnet run
on this. I intentionally included theLanguage
element because the project file might not necessarily need to be stored on disk for its language to be determined by its extension.The source file will have to be explicitly specified, even if only one source file exists in the current directory.
dotnet run
ning a source file will work with any .NET Language (C#/VB/F#). It will not deprecate tools like F# Interactive, because it will not be interactive in the REPL sense of the term and because it will compile the sources first, instead of interpreting them.dotnet run
ning a source file will not support more than one source files.dotnet run
ning a source file will not support custom NuGet packages. Languages like F# that get their source library from NuGet will behave as if no specificPackageReference
for that library was included.Like the actual
dotnet run
, the framework could be customized with the--framework
option and will default to the latest .NET (Core) version of the current SDK (after takingglobal.json
into consideration).dotnet run
ning a source file will support running in either Release or Debug mode (and even allow attaching a debugger).dotnet run
ning a source file will only support console apps. Libraries have no entry point and GUI apps typically need more than one file. CLI arguments will be passed after double dashes as usual.dotnet run
ning a source file will leave no trace in the file's directory. The compiled assembly will be cached somewhere else. Successivedotnet run
s of the same source file with the same settings will not need a recompilation.dotnet run
ning a source file will not be extended to commands likedotnet build
ordotnet publish