[Proposal] Ignored Directives Support #8616
Replies: 16 comments 34 replies
-
I'm worried about BOM. The presence of the BOM before the shebang will prevent the script interpreter. Visual Studio for Win uses Encoding.Default (usually not UTF8) if the BOM doesn't present. |
Beta Was this translation helpful? Give feedback.
-
Sure, and we could certainly consider warning if the file uses anything other than UTF-8 w/o BOM. |
Beta Was this translation helpful? Give feedback.
-
I thought shebang was already supported... is it only in the .csx variant? |
Beta Was this translation helpful? Give feedback.
-
ah, looks like its only currently supported in the scripting mode. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I'm a little confused. Do "simple programs" not require a project file? How would a single file "script" in this manner establish references or change any compiler properties? This feels like trying to bridge a gap between C# "simple programs" and CSX, which already has this support plus the directive support to make it actually useful. Short of adding that directive support this feels extremely limited. Again, C# would benefit so much more from embracing CSX and improving the tooling support than it ever will by chasing CSX through some separate dialect that will always be much less capable. |
Beta Was this translation helpful? Give feedback.
-
I agree with @HaloFour without directives for assembly imports this might not be very useful. On the other hand having a script that downloads nuget packages or loading complex and somewhat big assemblies doesn't feel right for scripting. The only thing that I kind of see as a big plus is that you can just take the cs file to any machine architecture and call What is still unclear for me is if the purpose of this proposal is that the cs-file is being interpreted or is it going to be compiled on running it. If the purpose is to "just" interpreted on run, than I agree even more with @HaloFour we should focus on making csx a better experience. |
Beta Was this translation helpful? Give feedback.
-
I don't think it should introduce a new How about: /// <interpreter path="" /> Which will allow more complex definition, for example: /// <project target="net5.0">
/// <properties>
/// <nullable>enable</nullable>
/// </properties>
/// <items>
/// <package include="Newtonsoft.Json" version="12.0.3" />
/// </items>
/// </project> |
Beta Was this translation helpful? Give feedback.
-
The point is to use a syntax that existing shells already recognize,
otherwise there would be no benefit. Unix shells recognize shebang syntax
and it is widely used to enable a script file to instruct the shell in how
that file is to be interpreted. No shell will understand a C# comment or a
blob of XML.
…On Thu, May 28, 2020, 10:31 PM Steve ***@***.***> wrote:
How about:
/// <interpreter path="" />
I don't think it should introduce a new #! directive to C#, for C#
doesn't use # for comment syntax.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3507 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACNCMEWBCWZ6OAC346MHQHTRT4M6VANCNFSM4NMYL2BQ>
.
|
Beta Was this translation helpful? Give feedback.
-
I summarize my understanding of this proposal at followings. Is it right?
#!/bin/dotnet run
//+ <Project Sdk="Microsoft.NET.Sdk">
//+ <PropertyGroup>
//+ <TargetFramework>netcoreapp3.1</TargetFramework>
//+ </PropertyGroup>
//+ </Project>
/*
* In this example, it is assumed that dotnet-cli will interprets the comments start with `//+` as inline csproj
*/
using System;
Console.WriteLine("Hello, world!"); |
Beta Was this translation helpful? Give feedback.
-
The first point is correct, and is the only thing this proposal covers. This proposal makes no statement on how a program would communicate dependencies to a tool. |
Beta Was this translation helpful? Give feedback.
-
One of the design meetings says:
I'm not sure I agree, because this doesn't actually need official tooling to be useful, it's entirely possible to extend by anyone. Consider this: #!/bin/my-custom-program
using System;
Console.WriteLine("Hello, world!"); where One example could be: #!/bin/run-unit-test
[TestFixture]
public class Test {
[Test]
public void IsValid (int number)
{
Assert.AreEqual (42, number, "everything");
}
} where |
Beta Was this translation helpful? Give feedback.
-
The point is that without that tooling we don't know if this will be good enough to actually solve those cases. |
Beta Was this translation helpful? Give feedback.
-
I agree that the reference directive ( |
Beta Was this translation helpful? Give feedback.
-
What is it's not good enough? What if we do it, and a month later people try to use it and say it's not sufficient and it needs to change or be redone. We can't add features without some way of actually validating that it solves the problems we want it to solve. We need some actual tooling adoption to demonstrate it is sufficient. |
Beta Was this translation helpful? Give feedback.
-
To be honest, I don't really seem the advantage this has in the language over just using The idea of |
Beta Was this translation helpful? Give feedback.
-
Ignored Directives
Summary
As we move to allow C# statements in the top level of a file, it's reasonable to assume that we might someday get support for
dotnet run
ing a .cs file. For further use of C# as a scripting language in this vein, I propose that we introduce a new preprocessor directive who's purpose is to exist solely to be ignored by the language: the hashbang directive. Linux and Unix scripts will often use#!<path to interpreter>
in order to direct the program loader to the interpreter that can run them. We should add a similar ignore to the C# language.Detailed design
We introduce a new directive:
The language ignores the contents of the hashbang and reference directives and moves to the next line.
Drawbacks
Any change adds complication to the language. If we implement support for this and it starts appearing in files without actual scripting support, then it could be confusing for users expecting it to work.
Alternatives
N/A
Unresolved questions
#if
. We have a few options for this:Design meetings
Beta Was this translation helpful? Give feedback.
All reactions