Visual studio one project with several dlls as output?
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
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.
To expand upon Julien Hoarau's answer above, here is a solution that allows you to compile multiple DLL files from within a single project, and have those DLL files be compiled from multiple CS files. Just open your csproj file and add this before the </Project> tag:
<!-- Plugin Building -->
<!-- 1. Hardlink to NuGet References - CSC does not read HintPaths, so you will have to create these for all your packages -->
<ItemGroup>
<PluginReference Include="..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll" ><InProject>false</InProject></PluginReference>
<PluginReference Include="..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll" ><InProject>false</InProject></PluginReference>
<PluginReference Include="..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll" ><InProject>false</InProject></PluginReference>
<PluginReference Include="..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll" ><InProject>false</InProject></PluginReference>
<PluginReference Include="..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll" ><InProject>false</InProject></PluginReference>
</ItemGroup>
<!-- 2. Each Plugin CS Files -->
<!-- You see that each tag in here has it's own name starting with Plugin -->
<!-- We can reference that later e.g. as @(PluginBlue) to get an array list to pass to the CSC sources, allowing us to have multiple files -->
<!-- Plugin.Blue\**\*.cs gets all the files in the "Plugin.Blue" folder -->
<!-- Plugin.Green just has a specific file list -->
<ItemGroup>
<PluginBlue Include="Plugin.Blue\**\*.cs"><InProject>false</InProject></PluginBlue>
<PluginGreen Include="Plugin.Green\File1.cs"><InProject>false</InProject></PluginGreen>
<PluginGreen Include="Plugin.Green\File2.cs"><InProject>false</InProject></PluginGreen>
</ItemGroup>
<!-- 3. Build each Plugin -->
<Target Name="BuildPlugins">
<!-- Plugin Blue -->
<CSC Sources="@(PluginBlue)" References="@(PluginReference)" TargetType="library" OutputAssembly="$(OutputPath)Plugin.Blue.dll" EmitDebugInformation="true" />
<!-- Plugin Green -->
<CSC Sources="@(PluginGreen)" References="@(PluginReference)" TargetType="library" OutputAssembly="$(OutputPath)Plugin.Green.dll" EmitDebugInformation="true" />
</Target>
<!-- 4. Require Build on Solution Compile -->
<Target Name="AfterBuild" DependsOnTargets="BuildPlugins">
</Target>
This is my approach - it lets you keep everything organized at the bottom instead of spread out throughout the project file. Using
<InProject>false</InProject>
allows us to hide the files from the SolutionExplorer, and have a separate defined list of files instead of simply adding the plugin tag to the files we want. In your main solution, be sure to set the Build Action to "none" on all the files you are compiling in the plugin so there is no duplication in the main project file.
Some more reading about CSC:
https://msdn.microsoft.com/en-us/library/78f4aasd.aspx Command-line Building With csc.exe
https://msdn.microsoft.com/en-us/library/ms379563(v=vs.80).aspx Working with the C# 2.0 Command Line Compiler
https://msdn.microsoft.com/en-us/library/s5c8athz.aspx Csc Task
https://msdn.microsoft.com/en-us/library/7szfhaft.aspx MSBuild Conditions
I hope this is useful to someone.