2

Hi all I have Class Library project with some classes.

I would like to know how to compile each class to different DLL.

I don't want to create separate project for each dll,

I using this dll as plugins but these are very simple plugin and I don't want to create project for each plugins.

I am going to put all these dll in the same directory and load them dynamically,

Thank you

MoShe
  • 6,197
  • 17
  • 51
  • 77

5 Answers5

3

Create a seperate .cs file for each class.

Then create the DLLs just like it was suggested in Nygma7's answer by opening the Visual Studio Command Prompt, CD to the location of the .cs files and create the DLLs at the prompt: csc /target:library /out:test1.dll test1.cs etc..

TaW
  • 53,122
  • 8
  • 69
  • 111
1

Create a seperate Project for each class.

htoverkill
  • 89
  • 7
1

I don't think this is a good way to proceed but, anyway. You can exclude classes from your project and then compile.

You can also use compiler directives as:

#define Class1
#if Class1
class 1
{
}
#endif

#undef Class2
#if Class2
class 2
{
}
#endif

And then has either Class1 or Class2 compiled within the output DLL. But, this will not be as automated as you want. Can't figure other way.

Erre Efe
  • 15,387
  • 10
  • 45
  • 77
0

Two Solutions: 1 You can separate the classes creating a new project in your solution, you will create a Class library, that will generate a dll. Than you must go to references and add the new reference to the project.

You should think if this is a good solution, if you are going to use that class in others projects it's a good solution.

2 example of code...

using System;
namespace SimpleMaths
{
  public class Operations
  {
    public static int add(int a, int b)
    {
        return a + b;
    }

    public static int substract(int a, int b)
    {
        return a - b;
    }

    public static int multiply(int a, int b)
    {
        return a * b;
    }
  }
}

Now open Start>>VisualStudio2005/2008 >> Visual Studio tools>>Visual Studio Command Prompt.

Now in command Prompt Locate the Directory where you have saved the .cs file just created. Using CD command.

csc /target:library /out:File.dll test.cs

this will generate the dll file that you want

DadViegas
  • 2,263
  • 16
  • 12
-1

You need to stand back and think about what you're asking. You have several classes that are all part of a single project, but you want that project to be built into several different pieces. Why would you want to do that? One of two things is true about your code:

  1. Your classes are dependent on each other; i.e. Class1 depends on Class2. In this case, you do not want to build them into separate dlls because those dlls won't function on their own.
  2. Your classes are independent of each other; i.e. Class1 has no relationship with Class2. In this case, why are in they in the same project? These classes belong in their own project so that they can be built individually.

After reading your update, I suspect you're in case #2. You should separate your classes into their own projects as long as they don't depend on each other. You have said "I don't want to separate them", but you haven't said why. Do you have a reason why you don't want them separated? You can still have them all part of the same solution, and you can still build them all with a single command.

ean5533
  • 8,884
  • 3
  • 40
  • 64