简体   繁体   English

如何在app.config文件中设置相对路径?

[英]How to set relative paths in app.config file?

I am working on a project in which I have many text and xml files. 我正在一个项目中,其中有许多文本和xml文件。 I read those from my program at runtime. 我在运行时从程序中读取了这些内容。

I have kept paths to those files in app.config file, but all the paths are absolute paths like "C:\\my_project\\help_files\\rejectList.txt" . 我在app.config文件中保留了这些文件的路径,但是所有路径都是绝对路径,例如“ C:\\ my_project \\ help_files \\ rejectList.txt”。

If I keep only "\\help_files\\rejectList.txt" path, program throws filenotfound exception. 如果仅保留“ \\ help_files \\ rejectList.txt”路径,则程序将引发filenotfound异常。

Can anyone please tell me how to set relative paths in C# applications? 

I would like to set something like "$root\\help_files\\rejectList.txt" and at runtime $root should resolve to actual path. 我想设置类似“ $ root \\ help_files \\ rejectList.txt”的内容,并且在运行时$ root应该解析为实际路径。

Is there any way in .net to set paths like this?

Also, I have one more question. 另外,我还有一个问题。 I have some dll's also that are needed for my project. 我的项目也需要一些dll。 Where do people usually keep dll's? 人们通常在哪里存放dll? In same folder as that of the exe file or should we create one folder called "lib" and put dll's there? 在与exe文件相同的文件夹中,还是我们应该创建一个名为“ lib”的文件夹并在其中放置dll?

Thanks and Regards, Shekhar 谢谢,谢卡

answer 1: , check Path Class 答案1:检查路径类

answer2: keep your dll's in output directory of projects. 答2:将您的dll保留在项目的输出目录中。 debug / release 调试/发布

see below 见下文

Optimizing Visual Studio solution build - where to put DLL files? 优化Visual Studio解决方案的构建-将DLL文件放在哪里?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM