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.
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.
If your two DLLs have the same name, you are going to have to rename them. Such as Assembly1. dll and Assembly2. dll.
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.
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
In a project you add all plugins files
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>
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>
If you want to create the plugins library after each build, add an after build target :
<Target Name="AfterBuild" DependsOnTargets="BuildPlugins"> </Target>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With