简体   繁体   中英

How to properly use lib and reference options when compiling c# code via command line

I need to compile two files: server.cs and client.cs which use the file server.cs ; and so obtain two .exe file server.exe and client.exe in the Desktop.
Since, I am doing the compilation via code , I am calling the process from the Desktop directory: c:\\windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe .

After, I have read this topic: How to use references when compiling c# code via command line
I understood that for solve my problem I should use the reference option.

This is what I am doing:

c:\\windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe /t:exe /out:server.exe server.cs

In order to create the server.exe file, and it works.

c:\\windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe /t:library server.cs

In order to create the server.dll file, and it works.

c:\\windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe /lib:C:\\Users\\MyName\\Desktop\\ /r:server.dll /t:exe /out:client.exe client.cs

In order to create the client.exe file, but I got the following error:

"The type or namespace name 'server' could not be found (are you missing a using directive or an assembly reference?);"

Why don't you build the server.cs and client.cs together while building client.exe. Looks more natural (albeit less efficient) to me.
This way you don't build server.cs as an exe and as a dll, and hopefully solving your build issue

c:\\windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe /t:exe /out:server.exe server.cs

c:\\windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe /t:exe /out:client.exe client.cs server.cs

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