为什么骑手在 /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虽然我不知道如何设置它。
因为(看起来)你是 运行 在调试模式下编译的(所以输出在 bin\Debug\net5.0\
中)并且 "letter-template.txt"
将被搜索为相对路径并考虑输出文件夹作为根。
如果将 "letter-template.txt"
添加到项目中,您可以将其自动复制到输出目录 - 在解决方案资源管理器中右键单击它,然后将“复制到输出目录”选项设置为“如果更新则复制” ".
另请参阅:
- Build Configurations (Rider)
- How to: Change the build output directory (VS)
- How to include other files to the output directory in C# upon build?
我尝试使用 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虽然我不知道如何设置它。
因为(看起来)你是 运行 在调试模式下编译的(所以输出在 bin\Debug\net5.0\
中)并且 "letter-template.txt"
将被搜索为相对路径并考虑输出文件夹作为根。
如果将 "letter-template.txt"
添加到项目中,您可以将其自动复制到输出目录 - 在解决方案资源管理器中右键单击它,然后将“复制到输出目录”选项设置为“如果更新则复制” ".
另请参阅:
- Build Configurations (Rider)
- How to: Change the build output directory (VS)
- How to include other files to the output directory in C# upon build?