Mono框架shebang linux

发布于 2024-10-04 05:12:14 字数 209 浏览 0 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不打扰别人 2024-10-11 05:12:14

编辑:我刚刚注意到您想对单个源文件执行此操作 - 对于单个源文件。 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. /EDIT

You 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.

铃予 2024-10-11 05:12:14

我想你也许可以使用 update-binfmts< /code>mono 注册为(编译的)单声道程序的解释器。

尝试 update-binfmts --display 并查看输出是否包含以下内容:

cli (enabled):
     package = mono-common
        type = magic
      offset = 0
       magic = MZ
        mask =
 interpreter = /usr/bin/cli
    detector = /usr/lib/cli/binfmt-detector-cli

I think you may be able to use update-binfmts to register mono as the interpreter for (compiled) mono programs.

Try update-binfmts --display and see if the output includes something like:

cli (enabled):
     package = mono-common
        type = magic
      offset = 0
       magic = MZ
        mask =
 interpreter = /usr/bin/cli
    detector = /usr/lib/cli/binfmt-detector-cli
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文