简体   繁体   English

Visual Studio 2017 找不到解决方案中存在的文件夹

[英]Visual Studio 2017 can't find folder that exists in the solution

I have Visual Studio 2017 project in which I need to open a folder named Devdog.General, which is also included in my Solution.我有 Visual Studio 2017 项目,我需要在其中打开一个名为 Devdog.General 的文件夹,该文件夹也包含在我的解决方案中。 However, it won't recognize it as an existing folder and gives me a missing directory / namespace error when I try to import it.但是,当我尝试导入它时,它不会将其识别为现有文件夹,并给我一个缺少目录/命名空间的错误。 See screenshot for more info.有关更多信息,请参阅屏幕截图。 在此处输入图片说明

Try this button:试试这个按钮:

显示所有文件

I had a similar problem the other day and it had to do with files that Visual Studio didn't know were part of the project because they'd been created externally (and that included folders).前几天我遇到了类似的问题,它与 Visual Studio 不知道是项目一部分的文件有关,因为它们是在外部创建的(包括文件夹)。 Visual Studio could see them but it was hiding them from me. Visual Studio 可以看到它们,但它对我隐藏了它们

After clicking that button, you will be able to right click on the folder and select "include in project" which will include the files for compilation and navigation.单击该按钮后,您将能够右键单击该文件夹并选择“包含在项目中”,其中将包含用于编译和导航的文件。

First, try selecting any of your "*.cs" files inside this "General" folder and check in the "Properties" view if the Build Action is configured to Compile .首先,尝试选择此“General”文件夹中的任何“*.cs”文件,并检查“Properties”视图是否将Build Action配置为Compile Visual Studio will only compile your file if it has the correct build action. Visual Studio 只会编译您的文件,前提是它具有正确的构建操作。

Secondly, open that "*.cs" file and verify if the namespace defined inside it is correct.其次,打开“*.cs”文件并验证其中定义的命名空间是否正确。 For C#, folder structures don't matter much: what really matters is the namespace you have defined your classes in. You can define your classes in namespaces completely different than the folder they are included in your project.对于 C#,文件夹结构并不重要:真正重要的是您在其中定义类的命名空间。您可以在与它们包含在项目中的文件夹完全不同的命名空间中定义类。 That is completely arbitrary, and up to your organizational needs.这完全是任意的,取决于您的组织需求。

An image illustrating what you need to check (and where) follows.下面是一张说明您需要检查的内容(以及检查地点)的图像。

在此处输入图片说明

Things to Check检查事项
1.) Check the namespaces inside .CS files - they collectively create usable namespaces you are referencing - not folder names. 1.) 检查 .CS 文件中的命名空间 - 它们共同创建您正在引用的可用命名空间 - 而不是文件夹名称。 If you create a few files, then move them to a folder, and create newer files inside that folder they will have different namespaces.如果您创建几个文件,然后将它们移动到一个文件夹,并在该文件夹中创建新文件,它们将具有不同的命名空间。 The newer files will have the default Namespace value followed by .FolderName.较新的文件将具有后跟 .FolderName 的默认命名空间值。 So be sure to check that out.所以一定要检查一下。

2.) CSPROJs can get hosed and lose reference to folders that display in the UI. 2.) CSPROJ 可能会被控制并丢失对 UI 中显示的文件夹的引用。 Remove the folder from the project (through the VS2017 UI, right click and choose that option).从项目中删除文件夹(通过 VS2017 UI,右键单击并选择该选项)。 DO NOT DELETE.不要删除。 Then recreate the folder in the UI (it shouldn't let you, navigate to the folder directory manually and rename the folder.OLD temporarily).然后在用户界面中重新创建文件夹(它不应该让你手动导航到文件夹目录并临时重命名文件夹.OLD)。 Once the folder is rename, try recreating the folder.文件夹重命名后,请尝试重新创建文件夹。 Upon success move all your CS files into the new folder from folder.OLD.成功后,将所有 CS 文件从 folder.OLD 移动到新文件夹中。 After files and folders are back to where they were essentially, then in Visual Studio, "Add existing items" on your .cs files.在文件和文件夹恢复到原来的位置后,然后在 Visual Studio 中,在 .cs 文件上“添加现有项目”。 This recreates the CSPROJ references one by one.这将一一重新创建 CSPROJ 引用。

3.) Unload CSPROJ, right click and Edit CSPROJ to manually check all the .CS references in ItemGroups. 3.) 卸载 CSPROJ,右键单击并编辑 CSPROJ 以手动检查 ItemGroups 中的所有 .CS 引用。 Make sure its myfolder\\myotherfolder\\mycsfile.cs .确保它的myfolder\\myotherfolder\\mycsfile.cs

4.) Remove reference to other projects that contain namespace, and re-add them. 4.) 删除对包含命名空间的其他项目的引用,并重新添加它们。 Verifying, one by one, the namespaces begin reappearing in Intellisense as recognized.一一验证命名空间开始重新出现在已识别的 Intellisense 中。

5.) If you try the above step, close Solution, close Visual Studio, navigate to SLN folder container, and delete hidden folder .vs and then reopen everything. 5.) 如果您尝试上述步骤,请关闭解决方案,关闭 Visual Studio,导航到 SLN 文件夹容器,然后删除隐藏文件夹.vs ,然后重新打开所有内容。

What happens is sometime a folder rename or file transfer doesn't propagate to the .CSPROJ folder, a namespace then doesn't get intellisense cached, and errors galore show up.有时发生的情况是文件夹重命名或文件传输不会传播到 .CSPROJ 文件夹,然后命名空间不会被智能感知缓存,并且会出现大量错误。

Please check your folder name and namespace name.请检查您的文件夹名称和命名空间名称。 probably folder name and namespace did not match可能文件夹名称和命名空间不匹配

enter image description here在此处输入图片说明

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

相关问题 无法在Visual Studio 2017中的共享项目中创建文件夹 - Can't create folder inside Shared project in Visual Studio 2017 在 Visual Studio 2017 中找不到类图 - Can't find the Class Diagram in Visual Studio 2017 Visual Studio 2017找不到命名空间系统 - Visual Studio 2017 can't find namespace System 无法在Visual Studio解决方案的调试文件夹中运行应用程序? - Can't run application in debug folder of Visual Studio Solution? 如何在Visual Studio 2017解决方案中设置文件夹以在其中搜索DLL? - How to set folder in a visual studio 2017 solution for searching DLLs there? 无法识别解决方案文件夹中的Visual Studio 2017 Nuget.config - Visual Studio 2017 Nuget.config at solution folder not recognized Visual Studio 2010运行糟糕 - 无法找到解决方案 - Visual Studio 2010 runs awful - can't find solution 如何在Visual Studio解决方案的项目中检查文件是否存在于文件夹中 - How to check if file exists in a folder in my project in Visual Studio solution 找不到System.Deployment文件Visual Studio 2017 OpenCV - Can't find System.Deployment file Visual Studio 2017 OpenCV 我在Visual Studio 2017上找不到跨平台应用程序Xamarin - I can't find cross platform app Xamarin on visual studio 2017
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM