• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 787
  • Last Modified:

Class library Visual Studio 2008

I created a SDK in Visual Studio 2008 With a Class library project.
How do I make this a dll & use it in another project as a NameSpace ?
0
u2envy1
Asked:
u2envy1
  • 4
  • 4
  • 2
1 Solution
 
CuteBugCommented:
When you build the Class Library project, the output will be a DLL.

In order to use this DLL in another project, open the Solution explorer, Right Click on References and select Add Reference...

Click on the Browse Tab and browse to your DLL.

Now the reference will be added.

In the .cs file where you will be calling this DLL, add the following statement

using namespace <yourDLLNamespace>; (without the <> brackets)
0
 
adatheladCommented:
Just build the project and the dll will be created in the bin/debug or bin/release folder underneath the project folder dependent on whether you have the project set to build for debug or release.

Then, from your other project you just add a reference to the dll - in VS2008 -> Right click References folder under your other project, "Add Reference..."
0
 
u2envy1Author Commented:
Thx guys.......
If my projects name is UniBadger can a class with the same name in the UniBadger project exist ?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
adatheladCommented:
Yes, just create it within a different namespace...

i.e. this is entirely valid:

namespace ProjectA
{
public class UniBadger
{

}
}

namespace ProjectB
{
public class UniBadger
{

}
}
0
 
CuteBugCommented:
Yes it can exist.

If your Project's name is UniBadger, then Visual Studio will allocated the namespace as UniBadger.

So you can define a class of the same name. Just Right click on the Project and select Add > Class...

Just specify the name as UniBadger.cs and Visual Studio will add a new file in the name of UniBadger.cs and will define the class in the following way


namespace UniBadger
{

   class UniBadger
  {

   }
}

Outside your DLL you can refer to your class as UniBadger.UniBadger
0
 
u2envy1Author Commented:
CuteBug you so with me on this.
Outside your DLL you can refer to your class as UniBadger.UniBadger
So outside my DLL I refer to it like this ?

 UniBadger.UniBadger myBadge = new UniBadger.UniBadger();
Theirs no way I can refer to it like this ?

Using UniBadger;
UniBadger myBadge = new UniBadger();
0
 
CuteBugCommented:
Yeah you can refer to it like that if you add the using statement at the top.

Using UniBadger;
UniBadger myBadge = new UniBadger();
0
 
u2envy1Author Commented:
Im unable to refer to it like that with the using.
When I add the using I must still do this
Using UniBadger;
UniBadger.UniBadger myBadge = new UniBadger.UniBadger();
0
 
CuteBugCommented:
I am sorry I was wrong in my previous comment.

When the Namespace and the class are of the same name, The compiler always references the namespace instead of the class.

Thus it will always give the error
'UniBadger' is a 'namespace' but is used like a 'type'

There are two ways to avoid this:
1. You have to give the full name of the class i.e. UniBadger.UniBadger myBadge = new UniBadger.UniBadger();
2. You have to rename your class or namespace so that they do not have the same name and thus the compiler will not face an ambiguous situation.
0
 
u2envy1Author Commented:
Thx, Much appreciated !!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now