[英]Why the dll file in my application is not in the program forever ? I needed to copy it to d:\ to run my application frmo there
I have this application that start like this: 我有这样启动的应用程序:
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using DirectShowLib;
using System.Collections.Generic;
using Extracting_Frames;
using System.Windows.Forms;
In the application it self i did add a reference browsed and selected DirectShowLib-2005.dll Everything went ok untill i copied from my application directory debug the application exe file wich is in my case: LE.exe copied it to D:\\ 在应用程序中,我自己添加了浏览并选择DirectShowLib-2005.dll的引用,一切正常,直到我从应用程序目录中复制了调试应用程序exe文件为止(在我的情况下):LE.exe将其复制到D:\\
Once im running it im getting exception error. 一旦我运行它我得到异常错误。 So i copied to D:\\ also the file DirectShowLib-2005.dll and now its working. 所以我也将文件DirectShowLib-2005.dll复制到D:\\,现在它可以工作了。
The question is how do i make that the file DirectShowLib-2005.dll will be in the application forever without needing to copy it to any place on my hard disk when im trying to running my program from there ? 问题是当我试图从那里运行程序时,如何使DirectShowLib-2005.dll文件永远存在于应用程序中,而无需将其复制到硬盘上的任何位置? If its d:\\ E:\\ or any other location. 如果它是d:\\ E:\\或任何其他位置。
When Visual Studio builds your application it places everything it's needed to run it in the Output path specified for the targeted configuration (eg bin\\Debug\\
for Debug
configuration). 当Visual Studio生成应用程序时,它将运行它所需的所有内容都放置在为目标配置指定的输出路径中(例如, bin\\Debug\\
用于Debug
配置)。
Because the DLL is a shared library its code is not embedded in your application and any reference to it is resolved at run time. 由于DLL是共享库,因此它的代码未嵌入您的应用程序中,并且对它的任何引用都在运行时解析。
If you simply want to run your application from a different location, the easiest way is to copy everything from the output folder . 如果您只是想从其他位置运行应用程序, 最简单的方法是从输出文件夹复制所有内容 。
If you struggle to merge the dependencies with your code you can use ILMerge or SmartAssembly . 如果您难以将依赖项与代码合并,则可以使用ILMerge或SmartAssembly 。
Sometimes, some references might be critical for your application to start up properly but because Visual Studio does not copy all references to the output folder in most cases, you'll need to change the property of a reference CopyLocal
to True
so that the reference would be included in your application by default. 有时,某些引用对于您的应用程序正常启动可能至关重要,但是由于Visual Studio在大多数情况下不会将所有引用复制到输出文件夹,因此您需要将引用CopyLocal
的属性更改为True
以便引用可以默认情况下包含在您的应用程序中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.