I have a solution that contains 2 projects: a class library called plugin and a console app called myconsole. They both use a NuGet package i.e. log4net. They have to meet these requirements:
myconsoleis not allowed to referenceplugin.dll, but it needs to load it via reflection at run timeplugin.dllhas to be available in a directory calledpluginsthat is relative tomyconsole.exelog4net.dllhas to be available in a directory calleddllsthat is also relative tomyconsole.exe
I need this deployment to happen when I build the solution in the IDE. Ideally I need this file structure to be produced by the IDE build:
[Z:\Staging]
- [Dlls]
- log4net.dll
- [Plugins]
- plugin.dll
- myconsole.exe
I was thinking to update each project and add a MSBuild target that runs after the build to copy the content of the the output directory (bin\debug) to the destination directory that I need. This approach has some issues:
- It does not scale well if I need to add more projects with different deployment requirements.
- If the projects are built in parallel then they both need to copy
log4net.dllto the same location. If this happens at the same time then I get warnings because the file is in use and retries are attempted. It works eventually, but I take it as a hint that I am doing something wrong. To workaround this I could filter the project output to deploy only what is produced by the project - which means I am able to deploy onlymyconsole.exeandplugin.dll, but notlog4net.dll. I would have to deploy this one manually, probably after being done with both projects (solution-level event?). This seems too complicated...
What is the correct way to implement this in MSBuild?