C#、Mono (gmcs) 中包含文件
我正在用 C# 编写一个非常小的应用程序,我需要包含一个带有某些类的 .cs 文件。我该怎么做?我正在寻找一些相当于 PHP 的“包含文件”或 Python 的“从文件导入某些内容”的东西。显然“使用”是不够的,文件必须以某种方式链接。我真的不想使用 MonoDevelop 或 VisualStudio 启动一些新的超级巨大且完全无用的项目,我想继续使用简单的 gmcs 和命令行。
I'm writing a really small application in C# and I need to include an .cs file with some class. How do I do that? I'm looking for some equivalent to PHP's "include file" or Python's "from file import something". Obviously "using" is not enough and the file has to be somehow linked. And I really don't want to start some new super-huge-totally-useless project using MonoDevelop or VisualStudio, I would like to stay with simple gmcs and command line.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需在命令行中包含两个文件名,并确保命名空间相同,或者所包含文件的命名空间是通过 using 语句或完全限定引用导入的。然后,用于编译的命令行如下所示:
请注意,mono 命令行旨在支持与 Microsoft 编译器完全相同的语法(带有一些附加内容),因此这对它们都适用。
从根本上来说,这就是项目文件和 Visual Studio 正在做的事情(尽管经历了内存中的 msbuild 等效操作)
You simply include both file names on the command line and ensure that the namespaces are the same or that the namespace of the included file is imported via a using statement or via fully qualified references. Then the command line for compilation looks like this:
Note that the mono command line is designed to support the exact same syntax (with a few additions) as the Microsoft compiler so this is true for both of them.
Fundamentally this is what the project files and visual studio are doing (albeit going through an in memory msbuild equivalent)
有两种方法可以在 .NET(和 Mono)中“包含”文件
将多个文件编译在一起。
然后将文件一起编译为单个程序集
将 includeFile 编译为单独的程序集并从主程序集引用它
这样你就得到了两个程序集
There are two ways to "include" a file in .NET (and Mono)
Compile several files together.
then files are then compiled together to a single assembly
Compile the includeFile to a separate assembly and reference that from the main assembly
this way you get two assemblies