Visual Studio中更改NuGet程序包DLL的生成路径

一、在项目.csproj文件根元素内添加项

<ItemDefinitionGroup>
  <ReferenceCopyLocalPaths>
      <DestinationSubDirectory>lib\</DestinationSubDirectory>
   </ReferenceCopyLocalPaths>
</ItemDefinitionGroup>

二、在App.config文件根元素内添加项

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

三、在Program.cs文件Main方法中加入

AppDomain.CurrentDomain.SetData("PRIVATE_BINPATH", "lib");
AppDomain.CurrentDomain.SetData("BINPATH_PROBE_ONLY", "lib");
var m = typeof(AppDomainSetup).GetMethod("UpdateContextProperty", BindingFlags.NonPublic | BindingFlags.Static);
var funsion = typeof(AppDomain).GetMethod("GetFusionContext", BindingFlags.NonPublic | BindingFlags.Instance);
m.Invoke(null, new object[] { funsion.Invoke(AppDomain.CurrentDomain, null), "PRIVATE_BINPATH", "lib" });

如此,相关DLL生成路径便在lib目录下并自动检索相关DLL(多目录用分号分隔)。