1

A C# program uses .Net framework libraries or third party libraries by using directive in the C# code.

When compiling the program using csc,

  • how shall we specify the search path for the used libraries?

  • does the compiler search for the used libraries in some search order?

I am comparing csc to gcc and javac in terms of specifying search paths for libraries and searching order. For gcc and javac, there are multiple ways to specify search paths,

  • command line options to them, such as -L to gcc and -classpath to javac;
  • environment variables, such as LIBRARY_PATH for gcc and CLASSPATH for javac;
  • default paths, such as current directory, some system-wide directory

Does csc also have multiple ways, and have a search order between them?

Same questions if compiling the program using msbuild which calls csc.

Thanks.

  • _"...by using directive...."_ - well no it doesn't. It uses _references_ via `/reference xxxx`. https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-options/reference-compiler-option –  Oct 07 '17 at 21:19
  • Does the C# program need to use `using` in the C# code to use libraries? –  Oct 07 '17 at 21:22
  • Do many people actually directly use csc? I know it can be done but generally every .NET shop I've ever worked in used MSBuild. The .CSPROJ file would tell MSBuild which would tell CSC where to look for references. – Christopher Painter Oct 07 '17 at 21:24
  • @ChristopherPainter Thanks. I asked for learning purpose. Where can I find more about "The .CSPROJ file would tell MSBuild which would tell CSC where to look for references"? –  Oct 07 '17 at 21:27
  • https://github.com/Microsoft/msbuild/wiki/ResolveAssemblyReference – Christopher Painter Oct 07 '17 at 21:30

1 Answers1

0

how shall we specify the search path for the used libraries?

Use the /lib command line option.

Syntax

/lib:dir1[,dir2] 

dir1

A directory for the compiler to look in if a referenced assembly is not found in the current working directory (the directory from which you are invoking the compiler) or in the common language runtime's system directory.

dir2

One or more additional directories to search in for assembly references. Separate additional directory names with a comma, and without white space between them.

OP

Same questions if compiling the program using msbuild which calls csc

If you use msbuild you are more than likely using a .proj file so it would use the path setup for your environment I would expect

Tell me more

  • Thanks. (1) For gcc and javac, there are multiple ways to specify search paths: command line options to them, environment variables, and default paths. Does `csc` also have multiple ways, and have a search order between them? (2) How about the questions in my post when using `msbuild`? –  Oct 07 '17 at 21:25
  • Thanks. Does `csc` use other ways such as environment variables or default values for search paths, besides command line option `/lib`? –  Oct 07 '17 at 21:34