Reputation: 27703
I created a C# file and wish to compile it into a DLL for future use. However, this .cs file depends on another DLL. In my code inside my .cs file I am doing something like:
using anotherlib.dll;
When I try to compile it into a DLL, the compiler tells me that it can't find that anotherlib.dll (missing directive or assembly reference).
What is the right way to go about it?
I am using .NET 2.0.
Upvotes: 0
Views: 214
Reputation: 754545
You need to add a reference to that particular DLL.
If you are using Visual Studio try the following
using
statement to the desired namespaceIf you have the source for the DLL, it's much better to use a project reference than a file reference. Simply add the project to the same solution, repeat steps 1-2 above and select Projects instead of Browse.
If you are not using Visual Studio, then you need to pass the fully qualified path of the DLL to the compiler with the /r: flag.
Upvotes: 4
Reputation: 505
And one more thing is that, You may put that DLL( You are accessing in your code ) in the bin folder of your project where your project DLL is generating. Because suppose you are providing your DLL to others so you can easily give the bin folder. So He/She friendly use your DLL. And Never get error due to dependent DLL.
Upvotes: 0
Reputation: 11436
You need to reference it using /r. If you are using the command line compiler. Here's a link: http://msdn.microsoft.com/en-us/library/ms379563(VS.80).aspx
If you are using Visual Studio, you simple add it as a reference in your project.
Upvotes: 2
Reputation: 564333
You don't use the using statement in C# that way.
Using, in C#, refers to the namespace. You "include" the other DLL by "referencing" it in your project or compiler. If you're using Visual Studio, add "anotherlib.dll" as a project reference, and then do:
using TheNamespaceFromAnotherLibDLL;
Upvotes: 1
Reputation: 24167
A using
statement is for importing a namespace. You must also add an assembly reference to actually use the namespace. If you are using csc.exe
from the command line, you can specify an assembly reference with the command line argument /reference:filename.dll
. If you are using Visual Studio, you can right click on your project and select "Add Reference...".
Upvotes: 1
Reputation: 10917
Instead of saying "using" in your code, add it as an assembly reference. In Visual Studio right-click on "References" and add the DLL. Then in your code have "using" for the namespaces of the stuff in the DLL.
Upvotes: 0
Reputation: 57872
You need to right click on the project in "Solution Explorer" and click on "Add Reference".
Browse for its location and add it as a reference.
This MSDN reference should provide more information.
Upvotes: 0