将 DLL 构建到单独的文件夹

Build DLL to a separate folder

第一

There are several questions similar to this, but none have answers that solved my problem nor can I post in them. The closest one is in this question.

I found the answer here. And I am posting here so I can found it later.

问题:如何构建我的项目并将我的所有 Referenced Library 放在 lib 子文件夹中?

A 想要这个输出目录:

保持这样:

I found the answer here and transcribed here for the case of the link die.

在您的 App.config 文件中,插入:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="lib" />
    </assemblyBinding>
  </runtime>
</configuration>

然后转到 Project -> Properties --- 右键单击​​您的 Project,然后在 ContextMenu select Properties.

现在转到 Build Events 并在 Post-build event command line 文本框中添加以下代码(如下图所示)。

; Move all assemblies and related files to lib folder
ROBOCOPY "$(TargetDir) " "$(TargetDir)lib\ " /XF *.exe *.config *.manifest /XD lib logs data /E /IS /MOVE
if %errorlevel% leq 4 exit 0 else exit %errorlevel%

之后

建立你的项目,告别你的强迫症!