0

I'm working on a plugin system for my app (C#, WPF). My project structure is like this:

Solution 'App'
    Plugins (solution folder)
        Plugin1 project (dll)
        Plugin2 project (dll)
    MainApp project (WPF)
    PluginInterface project (dll)

I edited projects' properties to build them in a custom folder this way

Build
    Debug
        MainApp.exe
        PluginInterface.dll
        Plugins (folder)
            Plugin1.dll
            Plugin2.dll

As the plugins should implement Iplugin interface (in PluginInterface project), I added PluginInterface project to references for each plugin project. However, this causes Visual Studio to build a copy of PluginInterface.dll in Plugins folder while PluginInterface project's output path is just set to Build\Debug.

I also tried to reference to the PluginInterface.dll file in Build\Debug (not project) but the result is same (I didn't forget to delete all created files before build).

How should I prevent Visual Studio from duplicating PluginInterface.dll file?

AmirSina Mashayekh
  • 498
  • 1
  • 5
  • 21
  • You can't - its a dependency so you need to build the project with the dll and therefore it will be put in the output directory, i spend some time on this aswell. – sommmen May 19 '20 at 08:06

1 Answers1

1

You could always remove the file afterwards with an msbuild task;

https://learn.microsoft.com/en-us/visualstudio/msbuild/delete-task?view=vs-2019

Or with a post-build script;

del $(ProjectDir)\plugins\pluginInterface.dll

sommmen
  • 6,570
  • 2
  • 30
  • 51
  • Good but I prefer to prevent it from being created totally. And I want to know why is it created? Why Visual Studio copies it everywhere it is referenced? – AmirSina Mashayekh May 19 '20 at 08:11
  • @AmirSinaMashayekh because that's simply how it works. If you build a program with a dependency (the .dll) the outcome program needs the depedency to run. Therefore it will always be included. unfortunately as of now - there is no way to suppress this or to exclude it. – sommmen May 19 '20 at 08:56
  • You mean if I delete it, my app won't work anymore? As my app is not completed, I can't test it right now. Is there any way to use a dll in a specific folder? (for plugins: ..\PluginInterface.dll) – AmirSina Mashayekh May 19 '20 at 09:07
  • @AmirSinaMashayekh no i mean generally speaking any output of a c# project can only ever work with all its dependencies in place. Therefore msbuild (the build engine) always outputs the dependencies (mydep.dll). so if you create a project, add a dependency - it will result in it being added to the output and there is currently no way to supress this. – sommmen May 19 '20 at 09:11