visual-studio Visual Studio C# 文件中的工作目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3677355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Working Directory in Visual Studio C# file
提问by user358591
What exactly is Working Directoryin the properties of Visual Studio C# project.
Visual Studio C# 项目属性中的工作目录究竟是什么。
I have see a project where I right click and go to Propertiesand then I go to Debugtab, it shows me Working Directory where Author of the code has specified folder in local machine. I want to know what does that working directory means and what kinds of file will it store in that directory.
我看到一个项目,我右键单击并转到“属性”,然后转到“调试”选项卡,它显示了代码作者在本地计算机中指定文件夹的工作目录。我想知道该工作目录是什么意思,以及它将存储在该目录中的文件类型。
Thank you in advance.
先感谢您。
采纳答案by Laurens Ruijtenberg
The working directory of a project (and any Windows program in general) is the default place in which a program is looking up it's files. For example: My program has working directory C:\dir and tries to open test.txt, it would look in C:\dir\test.txt.
项目的工作目录(以及一般的任何 Windows 程序)是程序查找其文件的默认位置。例如:我的程序有工作目录 C:\dir 并尝试打开 test.txt,它会在 C:\dir\test.txt 中查找。
So every opened file will be opened relative to the working folder.
因此,每个打开的文件都将相对于工作文件夹打开。
回答by Brian R. Bondy
Every process has a current Working Directory which is where all relative paths will be formed from. If not specified, this directory is the directory in which the active application started.
每个进程都有一个当前的工作目录,所有相对路径都将从该目录中形成。如果未指定,则此目录是活动应用程序启动的目录。
You can check which directory is set by calling:
您可以通过调用来检查设置了哪个目录:
System.IO.Directory.GetCurrentDirectory();
System.IO.Directory.GetCurrentDirectory();
As mentioned above in a comment by @0xA3 this setting has no effect to your deployed product, it is is only for debugging.
正如上面@0xA3 的评论中所述,此设置对您部署的产品没有影响,它仅用于调试。
回答by ChrisW
I think it will store nothing there, unless you add/write code in your application which explicitly creates files, either explicitly in the application's working directory, or implicitly specifying only a filename without specifying a directory at all.
我认为它不会在那里存储任何内容,除非您在应用程序中添加/编写显式创建文件的代码,或者在应用程序的工作目录中显式创建文件,或者仅隐式指定文件名而不指定目录。

