What does adding a reference to csproj file do?

yuvalm2 picture yuvalm2 · May 10, 2017 · Viewed 8.2k times · Source

Would it be accurate to say that a given DLL contains a bunch of namespaces (With classes, constants, functions etc. in each), and that referencing the dll in a csproj allows using them in .cs files belonging to that project?

I tried searching the web, but was unable to find answers which satisfied me. (Probably because the question is very basic)

Answer

Koby Douek picture Koby Douek · May 10, 2017

The simple answer to your question is yes.

In order to use an external or a 3rd party component in your IDE, you must first add a reference to it.

Once you added an assembly reference, you will be able to use its methods and properties in your code, by explicitly referring to them:

someNamespace.someClass.someMethod();

Or by using the using statement at the beginning of your code file and simplifying the reference call:

using someNamespace.someClass;

someMethod();

Adding a reference (in Visual Studio)

To add a reference in Visual Studio, right click the "references" folder > choose "add reference" and then "Browse" to you DLL.


Examining existing references

In Visual Studio, in the Project Explorer Pane, you can view the details about a reference (such as the version and its location) by expanding the References folder, right-clicking a reference, and selecting Details.