防止 Visual Studio 复制引用的 dll

Prevent Visual Studio from duplicating referenced dll

我正在为我的应用程序(C#、WPF)开发一个插件系统。我的项目结构是这样的:

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

我编辑了项目的属性,以这种方式在自定义文件夹中构建它们

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

由于插件应该实现 Iplugin 接口(在 PluginInterface 项目中),我将 PluginInterface 项目添加到每个插件项目的引用中。但是,这会导致 Visual Studio 在 Plugins 文件夹中构建 PluginInterface.dll 的副本,而 PluginInterface 项目的输出路径仅设置为 Build\Debug.

我也尝试引用 Build\Debug(不是项目)中的 PluginInterface.dll 文件,但结果是一样的(我没有忘记在构建之前删除所有创建的文件)。

我应该如何防止 Visual Studio 复制 PluginInterface.dll 文件?

之后您始终可以使用 msbuild 任务删除该文件;

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

或者使用 post-构建脚本;

del $(ProjectDir)\plugins\pluginInterface.dll