Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual studio one project with several dlls as output?

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.

like image 742
Aleksi Avatar asked Oct 05 '10 19:10

Aleksi


People also ask

How do I use DLL in another project?

Solution 1Add a reference to the DLL directly to your new project: open your project in VS, expand the Project branch in the Solution explorer, then right click "References". From the context menu, select "Add Reference..." and wait for the dialog - If can take a little while to appear.

How do I use two DLLs with the same name?

If your two DLLs have the same name, you are going to have to rename them. Such as Assembly1. dll and Assembly2. dll.

Should DLLs be in source control?

Some companies have a policy to put commonly used assemblies (DLL's) into source control. If you own the source code, this should never be done. These assemblies should be built during the build process.


2 Answers

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> 
like image 121
Julien Hoarau Avatar answered Sep 28 '22 06:09

Julien Hoarau


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.

like image 43
BrunoLM Avatar answered Sep 28 '22 05:09

BrunoLM