当前工作目录是Visual Studio目录
我正在构建一个类库,它引用其工作目录中的文件。但是,它无法找到该文件,因为它一直在 C:\Program Files\Visual Studio 2010\Common7\IDE\
中查找。解决方案不在该目录中,工作目录也没有设置为该目录。我在该文件夹中也看不到与我的类库相关的任何内容!
无论我在构建文件路径时是否使用Environment.CurrentDirectory,都会发生这种情况。
有人知道为什么会这样做吗?
I'm building a class library which references a file in its working directory. However, it's unable to find the file because it keeps looking in C:\Program Files\Visual Studio 2010\Common7\IDE\
. The solutions is not in that directory, nor is the working directory set to that. I can't see anything related to my class library in that folder either!
This happens whether I use Environment.CurrentDirectory
or not, when constructing my file path.
Does anybody know why it might be doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从它的声音来看,您希望在构建文件路径时使用
Application.StartupPath
,因此类似于;如果您想将当前目录设置为正确的目录(尽管我个人建议使用 Application.StartupPath 而不是相信当前目录是正确的),您可以这样做;
至于为什么,我有时会执行一些操作,例如打开文件打开对话框,然后导航到另一个位置,然后该位置将成为当前目录。
From the sounds of it you want to be using
Application.StartupPath
when constructing your file path so something along the lines of;If you want to set the current directory to the right directory (although personally I would recommend using the
Application.StartupPath
rather than trust the current directory will be right) you can do this;As for why, I've had occasions where you do something like open a file open dialog then navigate to another location, which then becomes the current directory.