5

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)

yuvalm2
  • 866
  • 2
  • 10
  • 27
  • 2
    Yes, that would be correct. – Koby Douek May 10 '17 at 08:14
  • 5
    Yes, that's what it means - it is essentially "I want to consume this stuff in this module here"; note that it is increasingly common to use package references (to sources like NuGet) rather than assembly references - especially in the "new new csproj" world. Same concept, different logistics. – Marc Gravell May 10 '17 at 08:15
  • Possible duplicate of [Call function from DLL?](http://stackoverflow.com/questions/5010957/call-function-from-dll) – default May 10 '17 at 08:21
  • 1
    @Default That is not a duplicate of that. The PO was not asking **how** to add a reference. – Koby Douek May 10 '17 at 08:31
  • @Default - This is not a duplicate of Dominik Antal's question "Call function from DLL?". Firstly, since the referred question does not deal with projects, but standalone c# scripts. In addition, it only discusses calling functions form DLL, while referencing a dll allows accessing more than functions. – yuvalm2 May 10 '17 at 08:59
  • @KobyDouek if you read it reversed it does sound like a duplicate to me. the answer to that question says: "Add the DLL via the solution explorer then it should be available." Which is what OP is asking ("what happends when I add a DLL?") and the question in the duplicate is basically "I'm trying to [use a] DLL [..] in my program." which is thus the answer. – default May 10 '17 at 09:05
  • @yuvalm2 none of the questions are referring to any scripts. – default May 10 '17 at 09:08

2 Answers2

4

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.

Koby Douek
  • 16,156
  • 19
  • 74
  • 103
1

Thats correct.

When we add a reference of an existing project / dll (normally using visual studio) its entry is added into the .csproj file.

One of the web project's csproj file I was working on that has dependency on the DataAccess project is shown below:

...
    <ItemGroup>
        <ProjectReference Include="..\WebStore.DataAccess\WebStore.DataAccess.csproj">
          <Project>{D7FBB6E0-C321-4BB3-A3D7-A78UUU04887E}</Project>
          <Name>WebStore.DataAccess</Name>
        </ProjectReference>
//    ... other references...
      </ItemGroup>

I would presume the same would be true for VB.Net projects. Hope this helps!

Yawar Murtaza
  • 3,655
  • 5
  • 34
  • 40