【问题标题】:c# built-in function to get path of bin folder and not the application folder such as bin\Debug or bin\Releasec# 内置函数获取 bin 文件夹的路径,而不是应用程序文件夹,例如 bin\Debug 或 bin\Release
【发布时间】:2019-05-25 03:05:43
【问题描述】:

我们可以得到应用程序目录的路径如下。但这为我们提供了基于应用程序发布模式调试的...\bin\Debug...\bin\Release。问题:我们如何获得bin 文件夹的路径没有 进行字符串操作 - 即是否有内置函数?

string path = AppDomain.CurrentDomain.BaseDirectory;

【问题讨论】:

  • “bin”文件夹仅在 VS Studio 的上下文中相关,更具体地说,因为 MS Build 的输出路径代表您运行 VS。查看项目属性的“构建”选项卡;您可以将相对路径更改为您想要的任何内容;即它不需要命名为“bin”。你想通过这条路达到什么目的?

标签: c# wpf winforms


【解决方案1】:

不,没有这样的功能,因为 bin 文件夹没有必要一直在那里。

AppDomain.CurrentDomain.BaseDirectory 返回执行代码的当前目录。从 Visual Studio 运行时,默认情况下为 ...\bin\Debug(或 ...\bin\Release),但并非总是如此。

如果您的目标是在不进行字符串操作的情况下从当前基目录向上一级,您可以尝试这样的事情(如回答 here

string dirName = AppDomain.CurrentDomain.BaseDirectory; // Starting Dir
FileInfo fileInfo = new FileInfo(dirName);
DirectoryInfo parentDir = fileInfo.Directory.Parent;
string parentDirName = parentDir.FullName; // Parent of Starting Dir

【讨论】:

    猜你喜欢
    • 2011-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-19
    • 2014-03-27
    • 2010-09-13
    相关资源
    最近更新 更多