tags:

views:

71

answers:

6

Hi, Say we have a class library project containing 10 classes. Now I want to create a dll which should contatin only 6 classes out of those 10. How we can achieve this?

A: 

Exclude them from project and build. Pick the dll from Debug or Release folder.

Ramiz Uddin
+7  A: 

You could use compiler directives. E.g.

#define ClassA
#if ClassA
class A
{
}
#endif

#undef ClassB
#if ClassB
class B
{
}
#endif

Class A would be included and Class B would not.

AdamRalph
A: 

you can check your language's command line compiler switches.

Ozan BAYRAM
A: 

Place the unnecessary classes inside a #ifdef EXTRA ... #endif bracket and you can then define EXTRA or not during compilation to get those additional classes.

Tarydon
+1  A: 

Assuming you follow the common practice of putting one class in one source code file: select the classes you don't want to include in Solution Explorer and set their Build Action property to None.

Hans Passant
+1  A: 

I'd create a second project file in a nearby folder and point it at the six source files containing the classes you want. This way you end up with two binaries with different names and version numbers, which will make life MUCH less confusing later on.

Otherwise you risk someone putting the wrong binary down, and either shipping four classes you want to keep hidden, or failing to ship four classes that are acutally needed.

Come to think of it, you don't mention whether there's any interaction between the six you want and the four you don't want. Assuming there isn't, just pull the six out into a separate project and have two "class library" binaries, one with six and one with four. That way there's no duplication of functionality or possible confusion about which binaries contain which classes.

Xav
Most of the classes are unrelated, and main purpose behind doing this is, I don't want to ship unrelated utility classes to client side.
Myth
Then I'd definitely say split them into separate binaries and spare yourself a lot of pain later on when folks get confused about which class is supposed to come from which binary or which binary they need to ship to get which combination of classes.
Xav
Ok, Let me tell you the scene. Classes are less ( 7-8 ), All are utility classes, so i have put them into a dll called utils. Now for a project 2-3 classes are not required. I don't want to ship these 2-3 classes to clients who don't require them. What should be the best strategy?
Myth
Useless but short answer: it depends!If you've got lots of apps that are already shipped against this common class library, and intend shipping new versions of those apps, then actually shipping the 2-3 unnecessary classes is probably the lesser evil.If this is the first time utils.dll has shipped, then I'd split it now and put the six you want to ship into one binary with a more meaningful name than "utils" and put the other four into a second binary with a different meaningful name.
Xav