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?
views:
71answers:
6Exclude
them from project and build
. Pick the dll
from Debug
or Release
folder.
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.
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.
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.
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.