我正在从事一个项目,其中有许多文本和 xml 文件。我在运行时从我的程序中读取那些。
我在 app.config 文件中保留了这些文件的路径,但所有路径都是绝对路径,如 "C:\my_project\help_files\rejectList.txt"。
如果我只保留“\help_files\rejectList.txt”路径,程序会抛出 filenotfound 异常。
Can anyone please tell me how to set relative paths in C# applications?
我想设置类似“$root\help_files\rejectList.txt”的内容,并且在运行时 $root 应该解析为实际路径。
Is there any way in .net to set paths like this?
另外,我还有一个问题。我的项目也需要一些 dll。人们通常把 dll 放在哪里?在与 exe 文件相同的文件夹中,还是我们应该创建一个名为“lib”的文件夹并将 dll 放在那里?
感谢和问候, 谢卡尔
最佳答案
答案 1:,检查 Path Class
answer2: 将您的 dll 保存在项目的输出目录中。调试/发布
见下文
Optimizing Visual Studio solution build - where to put DLL files?
关于c# - 如何在 app.config 文件中设置相对路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2309303/