将.NET程序集从应用程序基目录移开?

时间:2021-03-16 13:36:29

I have a WinForms application with a bunch of third party references. This makes the output folder quite messy. I'd like to place the compiled / referenced dlls into a common subdirectory in the output folder, bin / lib - whatever - and just have the executables (+ needed configs etc) reside in the output folder.

我有一个带有大量第三方引用的WinForms应用程序。这使输出文件夹相当混乱。我想将编译/引用的dll放在输出文件夹中的公共子目录bin / lib中 - 无论如何 - 只需将可执行文件(+所需的配置等)驻留在输出文件夹中。

After some searching I ran into assembly probing (http://msdn.microsoft.com/en-us/library/4191fzwb.aspx) - and verified that if I set this up and manually move the assemblies my application will still work if they are stored in the designated subdirectory like so:

经过一番搜索,我遇到了程序集探测(http://msdn.microsoft.com/en-us/library/4191fzwb.aspx) - 并验证了如果我设置它并手动移动程序集,我的应用程序仍可正常工作存储在指定的子目录中,如下所示:

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

However, this doesn't solve the build part - is there any way to specify where referenced assemblies and compiled library assemblies go?

但是,这不能解决构建部分 - 是否有任何方法可以指定引用的程序集和已编译的库程序集的位置?

Only solutions I can think of off the top of my head is either post-build actions or dropping the idea and using ILMerge or something.

只有我能想到的解决方案才是构建后的操作或放弃想法并使用ILMerge或其他东西。

There has got to be a better way of defining the structure :-)

必须有一种更好的方法来定义结构:-)

1 个解决方案

#1


1  

If you're building within Visual Studio, you can definitely set up post build actions - they work quite nicely. I don't really think there's any other good, documented way to do this. Unfortunately, when you reference another assembly, there's no option to define where to copy that referenced DLL to in the build process, I believe.

如果您在Visual Studio中构建,那么您肯定可以设置构建后的操作 - 它们可以很好地工作。我真的不认为有任何其他良好的,有记录的方式来做到这一点。不幸的是,当你引用另一个程序集时,我认为没有选项来定义在构建过程中将引用的DLL复制到何处。

Of course, if you're building those assemblies from source code, you could just set up their output directory to be (app)\bin or (app)\lib from the beginning, and the build process would spit them into the right directory right from the get go.

当然,如果你是从源代码构建那些程序集,你可以从一开始就将它们的输出目录设置为(app)\ bin或(app)\ lib,并且构建过程会将它们吐出到正确的目录中从一开始就是这样。

If you're using a more sophisticated build server, you probably have means of moving a handful of DLL files to a separate directory in that tool, too.

如果您正在使用更复杂的构建服务器,那么您可能还可以将少量DLL文件移动到该工具中的单独目录中。

#1


1  

If you're building within Visual Studio, you can definitely set up post build actions - they work quite nicely. I don't really think there's any other good, documented way to do this. Unfortunately, when you reference another assembly, there's no option to define where to copy that referenced DLL to in the build process, I believe.

如果您在Visual Studio中构建,那么您肯定可以设置构建后的操作 - 它们可以很好地工作。我真的不认为有任何其他良好的,有记录的方式来做到这一点。不幸的是,当你引用另一个程序集时,我认为没有选项来定义在构建过程中将引用的DLL复制到何处。

Of course, if you're building those assemblies from source code, you could just set up their output directory to be (app)\bin or (app)\lib from the beginning, and the build process would spit them into the right directory right from the get go.

当然,如果你是从源代码构建那些程序集,你可以从一开始就将它们的输出目录设置为(app)\ bin或(app)\ lib,并且构建过程会将它们吐出到正确的目录中从一开始就是这样。

If you're using a more sophisticated build server, you probably have means of moving a handful of DLL files to a separate directory in that tool, too.

如果您正在使用更复杂的构建服务器,那么您可能还可以将少量DLL文件移动到该工具中的单独目录中。