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

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

问题描述

我有我使用依赖注入来解决DLL文件之间的引用一个C#的解决方案。我有一个exe项目,未通过的exe文件(它使用的DLL通过IoC容器)中引用的一些其他的DLL项目。该项目设置为默认,Visual Studio设置它建立在它自己的文件夹中的每个DLL。既然EXE未引用的DLL,他们从来没有被复制到exe文件的输出目录,但没有得到国际奥委会的框架中。

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天全站免登陆