VB.Net使用.dll文件 [英] VB.Net Working With .dll Files

查看:96
本文介绍了VB.Net使用.dll文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Vb.net并不陌生,但这是我第一次处理.dll文件。



好​​的......是的...无论如何,我是菜鸟。



所以我使用的是DotNetZip .dll文件,我想要它提取文件(工作得非常好)



但显然你必须将.dll与.exe合并,或者你必须将.dll安装到计划与之共享程序的人的计算机上。



我尝试合并文件,但我个人不喜欢这个方法本身,想知道如何将.dll安装到个人电脑上。



现在我正在考虑将.dll安装到Programfiles \(foldername)\ dotnetzip.dll



使用特殊文件夹环境等。



但我的实际问题是......如何让程序检入程序文件? .dll并使用它?



我注意到它仅在.dll与.exe位于同一个文件夹中时才有效:(



有没有办法改变它?



谢谢大家。祝周末愉快:)

I'm relatively not new to Vb.net but this is my first time dealing with .dll files.

Okay... Yes... Whatever, I am a noob ._.

So I'm using a DotNetZip .dll file and I want it to extract files (which works really fine)

But obviously you have to either merge the .dll with the .exe, or you have to install the .dll onto the computer of the person who you are planning to share the program with.

I tried merging the files, but I personally don't like the method itself and would like to find out how to install the .dll onto the persons PC.

Right now I'm thinking to install the .dll into Programfiles\(foldername)\dotnetzip.dll

Using Special Folder Environment ect.

But my actual question is... How do I get my program to check in program files for the .dll and use it?

I noticed it works ONLY if the .dll is in the same exact folder with the .exe :(

Is there a way to change that?

Thank you guys. Have a very nice weekend :)

推荐答案

首先,.EXE和.DLL之间的区别在.NET中并不重要。中心概念是汇编。这些文件只是用作程序集模块的PE文件。程序集可以有多个模块,但Visual Studio项目通常只支持一个,这不是一个大缺陷。请参阅:

http://en.wikipedia.org/wiki/Portable_Executable [< a href =http://en.wikipedia.org/wiki/Portable_Executabletarget =_ blanktitle =New Window> ^ ],

http://msdn.microsoft.com/en-us/library/58scf68s.aspx [ ^ ],

http://msdn.microsoft.com/en-us /library/system.reflection.assembly.getmodule%28v=vs.110%29.aspx [ ^ ](高级,请参见下文)。



.EXE文件可以用作应用程序,因为它们具有平台知道的入口点 s,DLL可以用作类型库,但EXE可以完全相同的方式用作库。



库程序集不必入住。一个程序集可以引用其他程序集(使用Visual Studio,请参阅解决方案资源管理器的参考,添加引用),并使用它们与在同一程序集中完全相同,用于标记的类型和成员访问修饰符 public protected 。或者,可以使用 System.Reflection.Assembly 方法加载程序集。请参阅:

http://msdn.microsoft.com/en-us /library/ms973231.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.reflection.assembly%28v=vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/ms173121.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/wxh6fsc7.aspx [ ^ ]。



-SA
First of all, the distinction between .EXE and .DLL is not really significant in .NET. The central notion is assembly. These files are only the PE files used as assembly modules. An assembly can have more than one module, but Visual Studio projects usually support only one, which is not a big defect. Please see:
http://en.wikipedia.org/wiki/Portable_Executable[^],
http://msdn.microsoft.com/en-us/library/58scf68s.aspx[^],
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getmodule%28v=vs.110%29.aspx[^] (advanced, please see below).

The .EXE files can be used as the application as they have the entry point which the platform knows, and DLL can be used as a type library, but EXE can be used as a library in exactly the same way.

The library assemblies doesn't have to "checked in". One assembly can reference other assemblies (with Visual Studio, see Solution Explorer's "Reference", "Add Reference") and the use them exactly as it was in the same assembly, for the types and members marked by access modifiers public or protected. Alternatively, an assembly can be loaded using System.Reflection.Assembly methods. Please see:
http://msdn.microsoft.com/en-us/library/ms973231.aspx[^],
http://msdn.microsoft.com/en-us/library/system.reflection.assembly%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/ms173121.aspx[^],
http://msdn.microsoft.com/en-us/library/wxh6fsc7.aspx[^].

—SA


要与exe一起部署dll,您可以创建一个可帮助您创建自动设置过程的部署项目。

尝试

视频教程1 [ ^ ]

添加设置向导 [ ^ ]
To deploy dlls with exe's together, you can create a deployment project that will help you create an automated setup process.
Try
Video Tutorial 1[^]
Adding a Setup Wizard[^]


dimaba10000写道:
dimaba10000 wrote:

我原来的问题是,如果有可能让我的可执行应用程序检查用户计算机上特定文件夹中的.dll文件,使用它.dll文件作为参考。因为我不想将.dll和.exe保存在同一个文件夹中。

My original question was, if it was possible to get my executable application to check for .dll files in a specific folder on the users computer, to use that .dll file as a reference. Since I don't want to keep both .dll and .exe in the same folder.

你再次误解了。没有检查这样的东西。好吧,你可以通过使用像 Directory.GetFiles 之类的东西来检查,但是如果你想在运行时加载一些程序集并使用反射,这可能很有用。我不认为这是你想要的,你提到了参考(我不确定你已经准备好了。)



当你引用组件时,这是一个不同的故事:程序集由一些PE文件(您的DLL)的名称按名称引用,或者它们可以由强名称引用,并在某些目录(或在GAC中)中找到。所以,首先,我最好的建议是:忘记你的我不想将.dll和.exe保存在同一个文件夹中并且...实际上将它们放在同一个文件夹中 。注意你的解决方案是如何构建的:即使你的输出路径对于不同的项目是不同的(这不是很好;我总是建议将所有输出放在同一目录中;默认情况下这不是因为Visual Studio不能自动完成;并且所有内容都设计为在您通过其他项目引用项目后立即工作),Visual Studio会复制应用程序所在的所有引用的DLL。



我只能看到一种情况,当你想把一些库程序集放在一个单独的目录中时

:当你有多个产品使用这些库程序集时;当这些产品不必同时安装时,以及当您不想将您的库放在GAC中时。在这种情况下,其中一种可能的技术是使用带有 assemblyBinding 元素的配置文件



例如,假设您在不同的位置创建了一些目录,以及库文件所在的某个目录。假设你把一些应用程序组件,你的一个产品放在其他目录中(在我下面的例子中,它可能是同一级别上名为MyLibrary的目录,但它可以是任何相对路径,相对于你的应用程序组件文件)。您可以将配置文件添加到程序集文件中;它的名字是myApplication.exe,如果应该是myApplication.exe.config。在此文件中,您可以编写,例如:

You again misunderstood. There is not such thing as "check". Well, you can "check" by using something like Directory.GetFiles, but this can be useful if you want to load some assemblies during runtime and use reflection. I don't think this is what you want, you mentioned "reference" (and I'm not sure is you are ready).

When you reference assemblies, this is a different story: assemblies are referenced by the names of some PE files (your "DLLs") by name, or they can be referenced by strong names, and found in some directories (or in GAC). So, first and foremost, my best advice would be: forget about your "I don't want to keep both .dll and .exe in the same folder" and… actually put them in the same folder. Pay attention on how your solution is built: even if your output paths are different for different projects (which is not very good; I always advise to put all output in the same directory; this is not done this way by default just because Visual Studio cannot do it automatically; and everything is designed to work immediately after your reference your projects by other projects), Visual Studio copies all the referenced DLLs where the application is.

I can see only one case when you want to put some library assemblies in some separate directory
: when you have more than one product using those library assemblies; and when those products don't have to be installed at the same time, and when you don't want to put your libraries in GAC. In this, case, one of the possible techniques would be using config file with assemblyBinding element.

For example, let's assume you create some directories in different places, and some directory where your library files are. Suppose you put some application assembly, one of your products in some other directory (in my example shown below it could be the directory on the same level called "MyLibrary", but it could be any relative path, relative to you application assembly file). You can add a configuration file to your assembly file; it it's name is "myApplication.exe", if should be "myApplication.exe.config". In this file you can write, for example:

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



它将允许myApplication.exe搜索MyLibrary中名称引用的程序集文件,更确切地说,在搜索中添加此路径。



-SA


这篇关于VB.Net使用.dll文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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