简体   繁体   中英

A .NET DLL question

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.

You need to add a reference to that particular DLL.

If you are using Visual Studio try the following

  1. Right click on your project in solution explorer
  2. Select Add Reference
  3. Go to the Browse tab
  4. Navigate to the DLL location on disk and select OK
  5. You might need to add a using statement to the desired namespace

If 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.

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.

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...".

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;

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.

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.

  1. Firstly, you need to add assembly reference in your project.
  2. In Visual Studio right-click on "References" and add the DLL.
  3. After that you may access that DLL in your code by using keyword

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM