应用程序在调试模式下运行良好,但在发布模式下无法完全运行 [英] Application works fine in debug mode but not entirely in release mode

查看:80
本文介绍了应用程序在调试模式下运行良好,但在发布模式下无法完全运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.

我基于libvlc库制作音乐播放器.
我使用DLLs libcore和libvlc,以及安装在计算机上的VLC播放器中的插件.
在调试模式下,播放器将按我的要求播放音乐和视频.
但是在发行模式下,我什么都不会玩.为什么会这样?

插件位于项目文件夹下的资源文件夹中,
并且此代码用于获取它们(无论项目文件夹位于何处,因为即时消息将要在CD上交付我的项目):

Hello.

I making a music player based on the libvlc library.
I use the DLLs libcore and libvlc, and the plugins from the VLC player installed on my computer.
In debug mode, the player plays music and video as i should.
But in release mode, i wont play anything. Why is this?

The plugins are located in the resource folder beneath the project folder,
and this code is used to get to them (wherever the project folder is located, because im going to deliver my project on a CD):

String path = (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location));
path = path.Replace("\\bin\\x86\\Debug", "\\Resources");
path = "--plugin-path=" + path;
instance = new VlcInstance(new String[] { path });



两个DDL(libcore和libvlc)位于此文件夹中:

C:\ Users \ Trond \ Documents \ Hiof \ 6.学期\ dotNET \ VLCMediaPlayer \ VLCMediaPlayer \ bin \ x86 \ Debug

与此有关吗?

最好的问候,Trond:)



And the two DDLs (libcore and libvlc) are located in this folder:

C:\Users\Trond\Documents\Hiof\6. Semester\dotNET\VLCMediaPlayer\VLCMediaPlayer\bin\x86\Debug

Has it something to do with this?

Best regards, Trond :)

推荐答案

在任何情况下,绝对或相对的硬编码文件路径都不会有用.仅在开发过程中,才可以对代码的纯实验部分进行排除.摆脱路径,问题就会解决.

我可以看到的是:您正在尝试使用可执行程序所在的目录.尝试对其进行硬编码将无济于事.您需要计算输入程序集的主要可执行模块的位置.这是这样的:

There are no cases when a hard-coded file path, absolute or relative, can be useful. Exclusions can be made for purely experimental parts of the code, during development only. Get rid of paths and the problem will go.

What I can see is: you are trying to use the directory where your executable program is. Trying to hard-code it will never help. What you need is to calculate the location of a main executable module of your entry assembly. This is how:

string exeLocation = System.Reflection.Assembly.GetEntryAssembly().Location;
string exeDirectory = System.IO.Path.GetDirectoryName(exeLocation);


这种方式非常通用,可以容忍应用程序的托管方式和所有其他详细信息.还有其他方法不够精确.

另一种选择是使用嵌入在可执行文件中的资源,例如* .resx资源.

—SA


This way if very universal, tolerant to the way the application is hosted and all other detail. There are other methods which are not that accurate.

Another alternative is using resources embedded in an executable file, such as *.resx resources.

—SA


这篇关于应用程序在调试模式下运行良好,但在发布模式下无法完全运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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