简体   繁体   中英

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:\\

Once im running it im getting exception error. So i copied to D:\\ also the file DirectShowLib-2005.dll and now its working.

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 ? If its d:\\ E:\\ or any other location.

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).

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.

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 .

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.


屏幕截图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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