views:

79

answers:

3

I'm programming a project with plugin support. Since many of the plugins are relatively small (only one source-file/class) I would like to have them all in one project in visual studio, but to successfully do this I would need each source-file/class to be compiled into its own dll file, is this possible using visual studio?

If this is not possible with visual studio, would it be possible using another build system, while still coding and debugging with visual studio?

Currently I've set the plugins project output type to console, and programmed a main() method that will compile all .cs files in the source directory to dlls and copy those to the proper directory. Then I set that console app to be the post-build event of the plugins project. It works, but it seems like a very ugly hack.

Using visual studio 2010.

+6  A: 

You just have to create a Solution then add as many projects you want.

You can have like 5 Class Library projects and compile them, generating 5 DLLs.

BrunoLM
Yes, but creating 10 projects with each having one source-file seems like a terrible waste, I was hoping there was a way of compiling all the source-files in one project into separate dlls.
Aleksi
A waste of perhaps several kilobytes for the Project and AssemblyInfo files? Respectfully, we're talking false economy, here. This is what projects are *for*, to encapsulate your source code into assemblies. :)
djacobson
So there isn't an approach for you!
Sadegh
A: 

If you want each code file to be it's own DLL, then you have to make a new project for each code file. But you can put multiple project files (.csproj) into one big solution.

If this doesn't suite you, then you could always compile your project using the command line. That would allow you to customize your build to suite your needs. For instance you could write a batch scrip, or a powershell script that would compile all your code files into a separate DLL.

C Johnson
+2  A: 

You could create one project for each plugin and group all projects in a solution.

If you don't want to have one project per plugin, you could create a custom build with MSBuild using CSC task

How to generate a dll for each plugin file

  1. In a project you add all plugins files
  2. Edit the project file to specify which class will generate a plugin library :

    <ItemGroup>
      <Compile Include="Class1.cs">
        <Plugin>true</Plugin>
      </Compile>
      <Compile Include="Class2.cs" />
      <Compile Include="Class3.cs">
        <Plugin>true</Plugin>
      </Compile>
      <Compile Include="Program.cs" />
      <Compile Include="Properties\AssemblyInfo.cs" />
    </ItemGroup>
    
  3. Add a new target in your project file to generate the plugins library

    <Target Name="BuildPlugins">
      <CSC Condition="%(Compile.Plugin) == 'true'"
           Sources="%(Compile.FullPath)"
           TargetType="library"
           OutputAssembly="$(OutputPath)%(Compile.FileName).dll"
           EmitDebugInformation="true" />
    </Target>
    
  4. If you want to create the plugins library after each build, add an after build target :

    <Target Name="AfterBuild" DependsOnTargets="BuildPlugins">
    </Target>
    
madgnome
Does exactly what I wanted, thanks!
Aleksi