1

I would like to compile a C# program from the command line in a Linux terminal. My csc.exe is added to my Path and works correctly. The directory layout is as follows:

|-- Program.cs
|-- Otherfiles.cs
|-- bin
|    |-- Debug
|    |    |-- Newtonsoft.Json.dll

From the top directory, I use the following command to compile:

csc *.cs /r:./bin/Debug/Newtonsoft.Json.dll
--> error CS2001: Source file 'r:bin/Debug/Newtonsoft.Json.dll' could not be found

Is there a better way to do what I'm trying to do here, or will I just have to copy the .dll files I want into the same directory as Program.cs, as is done in this question?

Community
  • 1
  • 1
Dagrooms
  • 1,507
  • 2
  • 16
  • 42

1 Answers1

3

The /reference argument is only used to indicate the name of the assembly.

To specify additional directories to search for assembly files use the /lib argument:

csc *.cs /r:Newtonsoft.Json.dll /lib:"./dir with spaces/need quotes", ./bin/Debug

Use /lib to specify the directory in which one or more of your assembly references is located. The /lib topic also discusses the directories in which the compiler searches for assemblies.

rene
  • 41,474
  • 78
  • 114
  • 152
  • Very helpful, the Microsoft page on command line builds doesn't event include /r. https://msdn.microsoft.com/en-us/library/6ds95cz0.aspx – Dagrooms Jul 23 '15 at 16:09
  • Which I'm aware is a shortcut for some other command, it just isn't mentioned. – Dagrooms Jul 23 '15 at 16:09