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
Some poetry:
In my case - I needed to have plugin dlls
built for the unit test
project specifically.. If you do it the "normal way", by creating separate project for each plugin - then you will end up having more unit-test related projects than core assemblies.. So I think that in some cases it is worth doing multi-builds within same project. With that being said - I would like to provide an improved version of the accepted answer.
New approach improvements:
SDK
projects (used in .net Core)Create a new empty library project, make sure that the structure is following:
net472
hint: you can create .Net core project and change the target to net472
, for example.
Add a plugin and some references if needed, then, per following documentation, add: https://docs.microsoft.com/en-us/dotnet/core/tools/csproj
false
This will make it possible to manually include files for building.. otherwise the build will include all files by default.
Then explicitly add the item to be compiled:
true
Then, as mentioned in the following source - you can aggregate all references into a single string: How to get paths to all referenced DLLs in MSBuild?
To test:
Then you have to append a build target that is triggered on PostBuild:
The difference here you will notice is a References
property which basically translates the value into appropriate -reference argument for CSC compiler: https://docs.microsoft.com/en-us/visualstudio/msbuild/csc-task?view=vs-2019
bonus: you might incorporate this logic into your project even without having to explicitly define the Plugin
property..
According to this topic here: MsBuild Condition Evaluate Property Contains
It is possible to use Regex expression on build metadata: https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-well-known-item-metadata?view=vs-2019
So basically, something like this is allowed:
Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('%(Compile.Filename)', 'Plugin'))"
You can make it so, that if the Class filename contains a specific keyword, then you can trigger a separate compilation for such file.. Or if the file is located in specific folder! In example above if the file has word "Plugin" in it, then it will get picked up by CSC task.. I recommend checking metadata page to see all options.
bonus: If you just like me like being able to step up into the code and also to be able to output into the Debug
output window, you can also define:
DefineConstants="DEBUG;TRACE"
DebugType="full"
My latest configuration looks like this:
Hopefully it was useful for someone ;)
p.s. my thanks to original author for giving an example that I could improve upon.