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 ?
u2envy1Asked:
Who is Participating?
 
CuteBugConnect With a Mentor Commented:
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
 
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
u2envy1Author Commented:
Thx guys.......
If my projects name is UniBadger can a class with the same name in the UniBadger project exist ?
0
 
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
 
u2envy1Author Commented:
Thx, Much appreciated !!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.