Mono框架shebang linux
我有 ac# 源文件。有没有办法把类似 #!/usr/bin/env mono 的东西放在编译中,然后作为可执行文件运行:
例如,对于 python,我会这样做:
#!/usr/bin/env python
事实上,我想要的是运行编译后,脚本无需调用“mono the.exe”。我想要类似“./the.exe”的东西。
I have a c# source file. Is there any way to put something like #!/usr/bin/env mono, so it will be compiled and then run as executable:
For python for example, i'll do like this:
#!/usr/bin/env python
In fact, what I want is to run the script without calling "mono the.exe", after compiling. I want something like "./the.exe".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:我刚刚注意到您想对单个源文件执行此操作 - 对于单个源文件。 Mono 附带的
csharp
REPL 几乎支持这一点。然而,REPL 会抛出语法错误,因为它不理解 shebang 行并将其视为预处理器定义。如果我误解了并且您正在谈论已编译的程序集,则以下文本仍然适用。 /EDIT你不能使用shebangs,因为Mono生成的.exe文件是PE可执行文件,就像在Windows上一样。它们包含 CIL,而不是脚本。
不过,您可以做的是生成一个运行
mono your.exe
的小型 shell 脚本并使用它,或者您可以使用 Linux 内核的 binfmts 支持,如 此处。EDIT: I just noticed you want to do this for a single source file—for a single source file. This is almost supported by the
csharp
REPL that ships with Mono. However, the REPL spits out a syntax error because it doesn't understand the shebang line and sees it as a preprocessor definition. If I misunderstood and you were talking about a compiled assembly, the below text still applies. /EDITYou can't use shebangs, because .exe files produced by Mono are PE executables, just like on Windows. They contain CIL, not a script.
What you can do though is produce a small shell script that runs
mono your.exe
and use that, or you can use the Linux kernel's binfmts support, as outlined here.我想你也许可以使用
update-binfmts< /code>
将
mono
注册为(编译的)单声道程序的解释器。尝试 update-binfmts --display 并查看输出是否包含以下内容:
I think you may be able to use
update-binfmts
to registermono
as the interpreter for (compiled) mono programs.Try
update-binfmts --display
and see if the output includes something like: