繁体   English   中英

为什么 Rider 会在 /bin/debug/net5.0 中查找文件

[英]why does rider look for files in /bin/debug/net5.0

我尝试使用 txt 文件,但我的 ide 找不到它这是堆栈跟踪

Unhandled exception. System.IO.FileNotFoundException: Could not find file 'C:\Users\Tudor\RiderProjects\WinterInternship2022-Backend-main\SantaClauseConsoleApp\SantaClauseConsoleApp\bi
n\Debug\net5.0\letter-template.txt'.
File name: 'C:\Users\Tudor\RiderProjects\WinterInternship2022-Backend-main\SantaClauseConsoleApp\SantaClauseConsoleApp\bin\Debug\net5.0\letter-template.txt'
   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
   at System.IO.StreamReader..ctor(String path)
   at SantaClauseConsoleApp.Letter.createTextLetter() in C:\Users\Tudor\RiderProjects\WinterInternship2022-Backend-main\SantaClauseConsoleApp\SantaClauseConsoleApp\Core\Letter.cs:line
28
   at SantaClauseConsoleApp.Program.Question2() in C:\Users\Tudor\RiderProjects\WinterInternship2022-Backend-main\SantaClauseConsoleApp\SantaClauseConsoleApp\Program.cs:line 87
   at SantaClauseConsoleApp.Program.Main(String[] args) in C:\Users\Tudor\RiderProjects\WinterInternship2022-Backend-main\SantaClauseConsoleApp\SantaClauseConsoleApp\Program.cs:line 12

这是文件的调用

StreamReader reader = new StreamReader("letter-template.txt");

我也尝试了绝对路径,没有问题是搜索 window 虽然我不知道如何设置它。

因为(似乎)您在调试模式下运行编译(所以 output 在bin\Debug\net5.0\中)并且"letter-template.txt"将被搜索为相对路径,output 文件夹被视为根。

如果将"letter-template.txt"添加到项目中,您可以使其自动复制到 output 目录 - 在解决方案资源管理器中右键单击它并将“复制到 output 目录”选项设置为“如果较新则复制”。

也可以看看:

暂无
暂无

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

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