[英]Published C# Console App - The system cannot find the file specificied
我正在使用一个非常短的 C# 控制台应用程序来启动用 python 编写的可执行文件,这样我就可以利用单击一次部署。
在调试模式下,我能够找到作为资源包含的两个可执行文件。 但是,一旦应用程序发布,我似乎无法找到它们的相对文件路径。 我得到一个异常:“系统找不到指定的文件”
using System;
using System.Diagnostics;
namespace UpdateConsole
{
class Program
{
static void Main(string[] args)
{
string RunningPath = AppDomain.CurrentDomain.BaseDirectory;
string driver_path = string.Format("{0}Resources\\chromedriver.exe", System.IO.Path.GetFullPath(System.IO.Path.Combine(RunningPath, @"")));
string exe_path = string.Format("{0}Resources\\DUU.exe", System.IO.Path.GetFullPath(System.IO.Path.Combine(RunningPath, @"")));
Process.Start(exe_path,driver_path);
}
}
}
我也尝试过像这样引用资源:
Properties.Resources.DUU;
但这会返回一个 byte[] object 我不知道如何从这里提取相对文件路径。
string RunningPath = AppDomain.CurrentDomain.BaseDirectory;
此代码提供的文件路径根据构建模式而变化: 1. 在调试模式下,它是.../bin/Debug。 2. 在发布模式下是.../bin/Release。
因此,请确保将 .exe 文件复制到相应的文件夹中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.