C# - 使用不带引用的依赖注入时将 dll 复制到 exe 输出目录? [英] C# - Copy dlls to the exe output directory when using dependency injection with no references?

查看:27
本文介绍了C# - 使用不带引用的依赖注入时将 dll 复制到 exe 输出目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C# 解决方案,我使用依赖注入来解析 dll 之间的引用.我有一个 exe 项目和其他一些 exe 未引用的 dll 项目(它通过 IoC 容器使用 dll).项目设置是默认的 Visual Studio 设置,它在自己的文件夹中构建每个 dll.由于 exe 不引用 dll,它们永远不会被复制到 exe 的输出目录,也不会被 IoC 框架找到.

I have a C# solution that I am using dependency injection to resolve references between dlls. I have an exe project and some other dll projects that are not referenced by the exe (It uses the dlls through the IoC container). The project settings are the default, visual studio settings where it builds each dll in it's own folder. Since the exe doesn't reference the dlls, they never get copied to the output directory of the exe and don't get found by the IoC framework.

你是怎么处理的?您是否将它们全部构建在同一目录中?使用构建后复制命令?或者别的什么?

How do you handle this? Do you build them all in the same directory? Use post build copy commands? Or something else?

推荐答案

我通常使用构建后复制命令(使用 构建事件,所以它们是自动的)将依赖程序集放入共享文件夹.

I typically handle this by using a post-build copy command (using Build Events, so they're automatic) that puts the dependency assemblies into a shared folder.

然后我确保该文件夹包含在我的 IoC 容器的搜索路径中,以便找到它们.

I then make sure this folder is included in my IoC container's search path, so they get found.

另一个类似的选择是在您的主应用程序项目上使用构建事件.然后它可以将依赖项复制到适当的文件夹中.这样做的优点是允许在同一解决方案中为不同的应用程序使用不同的依赖项,同时仍然易于维护.

Another, similar option, is to use a build event on your main application project. It can then copy the dependencies into an appropriate folder. This has the advantage of allowing different dependencies to be used for different applications within the same solution, while still being easy to maintain.

这篇关于C# - 使用不带引用的依赖注入时将 dll 复制到 exe 输出目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆