We've recently added file-based apps to C#. Here's a sample:
#!/usr/bin/env dotnet
#:sdk Microsoft.Net.Sdk
#:package Newtonsoft.Json@13.0.3
#:property LangVersion=preview
using Newtonsoft.Json;
Main();
void Main()
{
if (args is not [_, var jsonPath, ..])
{
Console.Error.WriteLine("Usage: app <json-file>");
return;
}
var json = File.ReadAllText(jsonPath);
var data = JsonConvert.DeserializeObject<Data>(json);
// ...
}
record Data(string field1, int field2);
The above can be pasted into a .cs file and run with dotnet run app.cs, or on unix systems, the execute bit can be set and dotnet used as the "interpreter" to compile and build it.
See also dotnet-run-file.md.
We'd like to ensure that the tree-sitter grammar is updated to handle the new #! and #: elements nicely, including the sub-parts of specific directives such as #:package Name@Version, #:property Name=Value, etc. See VS Code's highlighting for example:
We merged dotnet/csharp-tmLanguage#337 and dotnet/roslyn#82627 to do this in the TextMate grammar and in Roslyn. Possibly those would be useful as a reference.
We've recently added file-based apps to C#. Here's a sample:
The above can be pasted into a
.csfile and run withdotnet run app.cs, or on unix systems, the execute bit can be set and dotnet used as the "interpreter" to compile and build it.See also dotnet-run-file.md.
We'd like to ensure that the tree-sitter grammar is updated to handle the new
#!and#:elements nicely, including the sub-parts of specific directives such as#:package Name@Version,#:property Name=Value, etc. See VS Code's highlighting for example:We merged dotnet/csharp-tmLanguage#337 and dotnet/roslyn#82627 to do this in the TextMate grammar and in Roslyn. Possibly those would be useful as a reference.