简体   繁体   English

如何编译两个C#代码

[英]How to compile two C# codes

I have 2 C# codes, file1.cs and file2.cs. 我有2个C#代码,file1.cs和file2.cs。 file2.cs uses the properties, methods and fields form file1.cs. file2.cs使用file1.cs形式的属性,方法和字段。 How can I compile this code? 如何编译此代码? I am not using Visual Studio. 我没有使用Visual Studio。 From online research it seems like both the files have to be in the same project. 从在线研究来看,这两个文件似乎必须位于同一项目中。 How do I accomplish this using command line as I am not using Visual Studio? 不使用Visual Studio时,如何使用命令行完成此操作?

Right now when I compile file1.cs like csc file1.cs it says 现在当我像csc file1.cs一样编译file1.cs时,它说

error CS5001: Program does not contain a static 'Main' method suitable for an entry point

This makes sens as file1.cs does not have any Main method. 由于file1.cs没有任何Main方法,因此很有意义。 The Main method exists in file2.cs. Main方法存在于file2.cs中。 When I compile file2 .cs like this csc file2.cs it says 当我像这样的csc file2.cs编译file2 .cs时,它说

error CS0103: The name 'MyCusVals' does not exist in the current context
warning CS0168: The variable 'Vals' is declared but never used

Both MycusVals and Vals are defined in file1.cs which is sitting in the same directory as file2.cs What is the correct syntax to compile file2.cs so that it can see file1.cs MycusVals和Vals都在file1.cs中定义,它与file2.cs位于同一目录中。编译file2.cs以便可以看到file1.cs的正确语法是什么?

You need to compile them together. 您需要将它们一起编译。 The csc command will compile a list of C# files all grouped together on the command line. csc命令将编译在命令行中分组在一起的C#文件的列表。 Life, by the way, is much easier with Visual Studio. 顺便说一句,使用Visual Studio可使生活更加轻松。 There's a free version you can download. 您可以下载一个免费版本。

You can still download the v2 .NET SDK: microsoft.com/en-us/download/details.aspx?id=19988 (and, that stuff should compile with a Framework 3.5.1 environment). 您仍然可以下载v2 .NET SDK:microsoft.com/en-us/download/details.aspx?id = 19988(并且,这些东西应该在Framework 3.5.1环境下编译)。 I'm not sure about the v2 version, but the v1.0 and v1.1 versions just used csc.exe and make files. 我不确定v2版本,但是v1.0和v1.1版本仅使用csc.exemake文件。 You could take a look at how those work 您可以看看它们的工作原理

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM