Reputation: 42002
When developing a C# applications in Visual Studio, I need to add a reference to the library I want to make use of before I can import it into the application with the using
keyword.
If I don't use Visual Studio, I can import libraries without having to add a reference to them first. Really my question has two points:
Why can't C# just import the libraries manually in Visual Studio (its clearly capable of working this way)?
What does adding a reference do for a project?, surely it can either find the library or it can't?
Upvotes: 4
Views: 114
Reputation: 1500615
If you look in the same directory as csc.exe
, you'll find a file called csc.rsp
. That lists all the references which are effectively automatically added. The C# compiler still needs to know what to look for - but it has a great big default list.
If you use the /noconfig
flag then you'll see the same behaviour as with Visual Studio - every reference has to be listed explicitly.
As for what adding a reference does to a project: it tells the C# compiler to use that library. That's all. Note that using
directives are to do with namespaces, not assemblies. They're often named the same, but they're completely separate concepts. A using
directive does not "import" a library - it just instructs the C# compiler to look for members within that namespace when resolving names.
Upvotes: 6