How to add a .dll reference to a project in Visual Studio
Asked Answered
L

5

87

I am just beginning to use the MailSystem.NET library. However, I cannot figure out where to add the .dll files so I can reference the namespaces in my classes. Can someone please help me? I am using Visual Studio 2010. Thank you for any information, there is so little online.

Longing answered 20/10, 2012 at 20:14 Comment(2)
Never underestimate open source, the code is the documentation. The author even checked-in the files he got when he upgraded his version of Visual Studio. Not knowing what files matter is a Big Red Flag. You'll need to know the code to fix the bugs.Jazminejazz
The question is not really about the code, it's about the build process. And some times, Visual Studio is tricky with us... But you've right to say that he may show us some compiler errors instead of code (or nothing like here).Mccown
A
92

Copy the downloaded DLL file in a custom folder on your dev drive, then add the reference to your project using the Browse button in the Add Reference dialog.
Be sure that the new reference has the Copy Local = True.
The Add Reference dialog could be opened right-clicking on the References item in your project in Solution Explorer

UPDATE AFTER SOME YEARS
At the present time the best way to resolve all those problems is through the
Manage NuGet packages menu command of Visual Studio 2017/2019.
You can right click on the References node of your project and select that command. From the Browse tab search for the library you want to use in the NuGet repository, click on the item if found and then Install it. (Of course you need to have a package for that DLL and this is not guaranteed to exist)

Read about NuGet here

Abstraction answered 20/10, 2012 at 20:17 Comment(5)
What is the dev drive?Murdoch
Where is browse button ?Annieannihilate
What "Manage NuGet packages" menu command? Is that on the main menu bar?Matrona
It is also on the main manu bar. It is in the PROJECT menu. But it is also on the popup menu that you get when you right click on a project name inside the Solution Explorer windowAbstraction
Hi all, for those still suffering from this issue, for me I just cannot find a browse button in the add reference window, and after googling, was unable to find a project properties window either to enable that button. In the end I just added the reference directly to the .csproj file, it's way easier this way.Issy
V
45

For Visual Studio 2019 and onward you may not find Project -> Add Reference option. Use Project -> Add Project Reference. Then in dialog window navigate to Browse tab and use Browse to find and attach your dll.

Add Project Reference

Click Browse button to access File Explorer

Voroshilovgrad answered 26/11, 2020 at 7:48 Comment(8)
Definite NO GO. I see 1) A top menu "Project --> Add Reference..." 2) on side of screen, Solution Explorer, myProjectName, References. I can right click and "Add Reference..." there. In either case I get a popup window entitled "Add Reference" with no place to add anything. There is a search box that finds nothing. No way to drag and drop. No way to enter anything of any sort. This is a totally dead popup. No browse tab that I can see. Can you explain? (or better yet provide a screen print in your answer?) Perhaps this is a C# only solution (I'm working in C++)? Many thx.Vivid
sure, zipzit , added screenshotsVoroshilovgrad
@SergiyVelychko, many thx. Your images make this quite clear. When I get to that popup its blank with no way to add information. I have to assume that's because I'm working on C++ console app and not a C# / .NET application. Thx again for taking the time to help confirm that.Vivid
@Vivid And yes, for C++ console project there is no Browse button for me as well.Voroshilovgrad
Thanks a lot. Just searched for "Microsoft.Management.Infrastructure" and chose the first one, selected it from the right, and hit the Install button. Worked like a charm.Solarize
For those with no browse button and can't find a project properties window to enable the browse button, you can also just add the reference directly to the .csproj file.Issy
Is there an update for visual studio 2022? Apparently upon right clicking on References > Add Reference I was greeted with nothing i.imgur.com/H4lg860.pngAntonio
Getting error while adding or browse showed my dll twice while I was looking for best folder to place my .dll. I checked project "Assemblys" removing not working once, placed a folder next to my inner project folder for the .dll, opened "Add>Project Reference>Browse" and clicked right on existing references removing them. Then (@Trung0246) I searched with file browsing dialog bottom right for my .dll again and now it is shown there plus added in "Assemblys" plus works when I enter "using MyLibrary;" plus Visual Studio generates an "ItemGroup" with reference to .dll in the csproj. (Use 2022)Wigeon
U
6

You probably are looking for AddReference dialog accessible from Project Context Menu (right click..)

From there you can reference dll's, after which you can reference namespaces that you need in your code.

Unprintable answered 20/10, 2012 at 20:17 Comment(0)
B
1

Another method is by using the menu within visual studio. Project -> Add Reference... I recommend copying the needed .dll to your resource folder, or local project folder.

Baltimore answered 4/8, 2020 at 13:13 Comment(0)
S
0

Project->AddReference will work if your DLL is a project in your solution.

In the editions of Visual Studio, a Browse option may not be available.

Browse is not available for C++ projects unless the Common Language support is enabled. For many C++ projects you may not want to enable this feature.

If Browse is not available, then your best bet is to copy the required DLLs to a folder in your solution and ADD THEM AS EXISTING ITEM to your project.

Then modify the properties of the item.

Set "Excluded from Build" to NO Set "Content" to YES Set "Item Type" to Copy file.

As other posters have suggested, you can also copy the DLL(s) directly to your Release or Debug folders.

That works just fine - unless you clone a fresh copy of your project from Git and find that Debug and Release folders are normally excluded and won't be in your new copy.

Or if NUGET is available with the required DLL, then use NUGET to obtain the DLL.

Spanishamerican answered 6/5 at 17:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.