简体   繁体   English

跨多个项目引用解决方案文件夹中的 txt 文件以进行作业分配

[英]Reference txt file in solution folder across multiple projects for homework assignment

Basics of assignment分配的基础

  1. Use Visual Studio (I'm in 2019, thank you school!)使用Visual Studio(我在2019年,谢谢学校!)
  2. Create console app that displays Magic 8 Ball style responses randomly to any text entered in line.创建控制台应用程序,随机显示 Magic 8 Ball 样式对行中输入的任何文本的响应。
    • This list is stored as a .txt file somewhere within the solution此列表存储为解决方案中某处的 .txt 文件
  3. Create windows form app that allows a user to enter new responses that are saved to the list pulled in the console app above创建 Windows 窗体应用程序,允许用户输入保存到上面控制台应用程序中拉出的列表中的新响应
    • This only accepts one line at a time with a listbox displaying the results and a save button for saving.这一次只接受一行,带有一个显示结果的列表框和一个用于保存的保存按钮。 Form has label ("Enter a magic response!"), text box for input, list box for displaying list from .txt file, and save button to add text box entry to .txt file.表单具有标签(“输入魔法响应!”)、用于输入的文本框、用于显示 .txt 文件列表的列表框以及用于将文本框条目添加到 .txt 文件的保存按钮。

I don't know how to reference across projects, and my developer lingo is still too underdeveloped for me to conduct a worthwhile Google search.我不知道如何跨项目引用,而且我的开发人员行话仍然太不发达,我无法进行有价值的 Google 搜索。 I simply don't know how to reference a relative path that keeps things contained.我只是不知道如何引用保持事物包含的相对路径。 I only know how to reference an absolute path:我只知道如何引用绝对路径:

StreamWriter outputfile;
outputfile = File.AppendText(@"C:\Users\...some-file-path...\Homework2\responses.txt)

Or deeper if it's in the bin\\debug folder.或者更深,如果它在 bin\\debug 文件夹中。 Speaking of, I don't care if it's in the debug folder of one project or another, or in the main solution folder.说起来,我不在乎它是在一个项目或另一个项目的调试文件夹中,还是在主解决方案文件夹中。

I just want it to work since it's homework (although an explanation of common industry best practices would not be unappreciated, even though I'm going into IT).我只是希望它能够工作,因为它是家庭作业(尽管对常见行业最佳实践的解释不会不受欢迎,即使我要进入 IT)。 How do I reference the solution folder as the start of the path to which I need to find a file?如何将解决方案文件夹作为我需要查找文件的路径的开头? I would ask if that's possible, but I know the reality of programming is that anything is possible if you're just willing to put enough knuckle grease into the project.我会问这是否可能,但我知道编程的现实是,只要您愿意在项目中投入足够的关节油脂,一切皆有可能。

You can use .. to go up a directory relative to the current one.您可以使用..上一个相对于当前目录的目录。 So going from C:\\Windows\\Temp using ..\\..\\ProgramData would get you to C:\\ProgramData .所以从C:\\Windows\\Temp使用..\\..\\ProgramData会让你到C:\\ProgramData

The current dir is referenced with .\\ for going downwards in the tree.当前目录用.\\引用,用于在树中向下移动。 So using the previous example .\\Temp1 would get you to C:\\Windows\\Temp\\Temp1所以使用前面的例子.\\Temp1会让你到C:\\Windows\\Temp\\Temp1

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

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