简体   繁体   English

在bin文件夹内的文件夹内引用dll

[英]Reference a dll inside a folder within the bin folder

Inside my Bin folder I created another folder called "Template" (Bin > Template). 在我的Bin文件夹中,我创建了另一个名为“模板”的文件夹(Bin>模板)。 Inside the Template folder I have a set of dll's, of which I would like to call from a class; 在Template文件夹中,我有一组dll,我想从一个类中调用它。 like... using Bin.Template.Example.ClassName; 像... using Bin.Template.Example.ClassName; Is it possible to accomplish this? 有可能做到这一点吗?

Yes you can use Assembly.LoadFile to load external assemblies. 是的,您可以使用Assembly.LoadFile加载外部程序集。

        var x = Assembly.LoadFile("myFile.dll");
        var myObject = x.CreateInstance("MyClass");

However you will not have strongly typed access to the resulting object. 但是,您将没有对结果对象进行强类型访问。

Consider using dependency injection instead, where you will be able to load assemblies and know the types. 考虑改用依赖项注入,您将可以在其中加载程序集并了解类型。

To use an external DLL from the filesystem, you need to add a reference at the project level. 要使用文件系统中的外部DLL,您需要在项目级别添加引用。 Right click References under your project, and choose Add Reference... : 右键单击项目下的References ,然后选择Add Reference...

在此处输入图片说明

Then click Browse button, locate the DLL, press Ok . 然后单击“ Browse按钮,找到DLL,然后按“ Ok

Inside your class file, add using <dll.name.space>; 在类文件中, using <dll.name.space>;添加using <dll.name.space>; to the top. 到顶部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM