How to use lib and reference options correctly when compiling C # code via command line

I need to compile two files: server.cs and client.cs, which use the server.cs file; and therefore get two .exe files server.exe and client.exe on the desktop.
Since I am compiling using code , I call this process from the Desktop directory: c: \ windows \ Microsoft.NET \ Framework \ v4.0.30319 \ csc.exe.

After that, I read this topic: How to use links when compiling C # code through the command line
I realized that to solve my problem I have to use the link option.

This is what I do:

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

To create the server.exe file, it works.

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

To create the server.dll file, 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

To create the client.exe file, but I got the following error:

"Cannot find the name or namespace name of the server (do you miss the using directive or assembly references?);

+4
source share
1 answer

Why don't you build server.cs and client.cs together when creating client.exe. It looks more natural (albeit less effective) for me.
This way you are not creating server.cs as exe and as dll, and hopefully solves the build problem

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

-1

Source: https://habr.com/ru/post/1570066/


All Articles