yuvalm2
yuvalm2

Reputation: 984

What does adding a reference to csproj file do?

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)

Upvotes: 5

Views: 15305

Answers (2)

Yawar Murtaza
Yawar Murtaza

Reputation: 3865

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!

Upvotes: 1

Koby Douek
Koby Douek

Reputation: 16675

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.

Upvotes: 4

Related Questions