简体   繁体   中英

How to compile two C# codes

I have 2 C# codes, file1.cs and file2.cs. file2.cs uses the properties, methods and fields form file1.cs. How can I compile this code? I am not using 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?

Right now when I compile file1.cs like csc file1.cs it says

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. The Main method exists in file2.cs. When I compile file2 .cs like this csc file2.cs it says

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

You need to compile them together. The csc command will compile a list of C# files all grouped together on the command line. Life, by the way, is much easier with 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). I'm not sure about the v2 version, but the v1.0 and v1.1 versions just used csc.exe and make files. You could take a look at how those work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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