I have a C# project which contains ".csproj" file. I want to import/take reference of third party .dll. I am new to C#. Please suggest me the way to achieve this. Please let me know if you need any other information. Thanks in advance !
-
Is that third party dll managed (i.e. written on C# or other managed language for .NET environment) or native (i.e. written on unmanaged C++ etc)? – Andrey Korneyev Sep 18 '14 at 05:50
-
@Andy: I think that dll is written in PHP and I have that dll. Please let me know how can I use that dll – Varun Sep 18 '14 at 06:21
-
@Varun: I really doubt your dll was written in PHP because PHP is interpretted not compiled language. – Andrey Korneyev Sep 18 '14 at 06:31
3 Answers
Open the project explorer. Click on References. Right Click on References -> Add Reference -> add the dll which you want to add in your project.

- 1,129
- 6
- 6
-
Thanks for sharing this information. I am able to see my dll in "References" but I am not able to call any function of that dll. Do I need to write any import statement – Varun Sep 18 '14 at 06:56
-
"Right Click..." How is it done without a mouse? I have a `.csproj` file and no mouse. – lmat - Reinstate Monica Nov 17 '20 at 13:47
First of all, you need to understand, if your thirdparty dll managed (i.e. contains IL code for .NET platform) or unmanaged.
If that dll is managed then all you need is just add it to your project references and you can call it's methods.
To add it to references - open your solution in Visual studio, locate References
folder in your solution explorer, select Add reference
from context menu and then browse to your dll and add it.
If dll is unmanaged then you should not add it into references, but should add it to solution as a file. Just click on solution in solution explorer of Visual Studio and select Add
-> Existed item
from context menu.
Then you should reference it somethere in your code like this
[DllImport("your_dll_name.dll")]
public static extern void MyDLLFunction();
After this you can use MyDLLFunction() in your code. See MSDN for references.

- 26,353
- 15
- 70
- 71
-
Thanks for sharing this solution. But my code is not able to recognize "DllImport" – Varun Sep 18 '14 at 06:56
-
Ensure you've added `using System.Runtime.InteropServices;` in your file where you're plan to use DllImport. Also note that DllImport should be placed inside some class, not outside. – Andrey Korneyev Sep 18 '14 at 07:01
Welcome to the World of C Hashtag :)
- Right click on your project and choose Add Reference.
- When the dialog comes up,
- choose the Browse tab and go find your assembly (3rd party dll)
- After adding the assembly include that reference in your class or form where ever you are going to use

- 2,432
- 7
- 24
- 33