简体   繁体   English

Visual Studio - 项目显示为“杂项文件”

[英]Visual Studio - project shows up as "Miscellaneous Files"

This is a weird one.这是一个奇怪的问题。 I have a C# Class Library project within my solution.我的解决方案中有一个 C# 类库项目。 If I open a .cs file within this project, the Project drop-down on the code editor shows that it belongs to 'Miscellaneous Files'.如果我在这个项目中打开一个.cs文件,代码编辑器上的Project下拉菜单显示它属于“杂项文件”。

问题截图

Other symptoms: if I go to the properties of the project and look at Assembly Information , all values are blank, despite the values existing in the AssemblyInfo.cs file.其他症状:如果我转到项目的属性并查看Assembly Information ,所有值都是空白的,尽管AssemblyInfo.cs文件中存在值。

Both of these are annoying, but the problem is that这两个都很烦人,但问题是

  • I don't get intellisense on any files in the project我对项目中的任何文件都没有智能感知
  • I can't seem to step through it in the debugger (it tells me that the files do not belong to the solution and so can't be debugged).我似乎无法在调试器中逐步完成它(它告诉我文件不属于解决方案,因此无法调试)。

装配信息为空白

I have tried:我努力了:

  • Combing through the .csproj file and comparing to others in the solution (no joy)梳理.csproj文件并与解决方案中的其他文件进行比较(不高兴)
  • Re-creating the .csproj file and overwriting the old one (worked until I merged the branch into trunk, then the problem re-appeared)重新创建.csproj文件并覆盖旧文件(一直工作到我将分支合并到主干中,然后问题再次出现)
  • Banging my head on the keyboard (headache)用头敲键盘(头痛)

Google has turned up nothing.谷歌一无所获。 Does anyone have any ideas as to what's going on here?有人对这里发生的事情有任何想法吗?

How I solved my issue:我如何解决我的问题:

  1. Go to the file which appears as Miscellaneous Files inside Solution Explorer.转到解决方案资源管理器中显示为杂项文件的文件。
  2. Right-Click file and select Exclude from project.右键单击文件并选择从项目中排除。
  3. Right-Click your project/folder where the file was and click add Existing Item, and add the file you just removed back into your project.右键单击文件所在的项目/文件夹,然后单击添加现有项目,然后将刚刚删除的文件添加回项目中。

I have this issue in VS 2017 also.我在 VS 2017 中也有这个问题。
I found that this miscellaneous files are files added outside the VS.我发现这个miscellaneous文件是在VS之外添加的文件。 So if switch to another git branch (where there are new files) whithout closing the VS and click to "Reload" button in VS (when it checks that sln/csproj files are modified outside the VS) then these new files are not correctly parsed by VS and "marked" as miscellaneous .因此,如果在不关闭 VS 的情况下切换到另一个 git 分支(其中有新文件)并单击 VS 中的“重新加载”按钮(当它检查 sln/csproj 文件是否在 VS 之外被修改时),那么这些新文件没有正确解析由 VS 并“标记”为miscellaneous

As workaround I close VS, remove folder .vs from disk and run VS again.作为解决方法,我关闭 VS,从磁盘中删除文件夹.vs并再次运行 VS。 After VS will fully initialized these new files are parsed successfully. VS 将完全初始化后,这些新文件被成功解析。 Note this way clears you custom settings like StartUp Project and so on.请注意,这种方式会清除您的自定义设置,例如StartUp Project等。

Here is the Solution:这是解决方案:

  • Go to Options on the Tools menu and then select Documents in the Environment node.转到“工具”菜单上的“选项”,然后在“环境”节点中选择“文档”。 (If Documents does not appear in the list, select Show all settings in the Options dialog box.) (如果文档未出现在列表中,请在“选项”对话框中选择“显示所有设置”。)
  • Put a tick on " Miscellaneous files in Solution Explorer " and Click OK .勾选“解决方案资源管理器中的其他文件”,然后单击“确定”。 (This option displays the "Miscellaneous Files" node in Solution Explorer. Miscellaneous files are files that are not associated with a project or solution but can appear in Solution Explorer for your convenience if you tick this option.) (此选项在解决方案资源管理器中显示“杂项文件”节点。杂项文件是与项目或解决方案不相关的文件,但如果您勾选此选项,为了您的方便,杂项文件可以出现在解决方案资源管理器中。)
  • Locate your file in the Solution Explorer under "Miscellaneous Files".在“其他文件”下的解决方案资源管理器中找到您的文件。 Then drag and drop your file to where it should belong and voila!然后将您的文件拖放到它应该属于的位置,瞧! This will copy the file to where you drop it.这会将文件复制到您放置它的位置。 You may now safely delete the older file under Miscellaneous Files folder if you wish to do so.如果您愿意,现在可以安全地删除 Miscellaneous Files 文件夹下的旧文件。

Check that link https://www.reddit.com/r/VisualStudio/comments/b8vbj8/help_netf461_project_opened_in_vs2019_all_files/检查该链接https://www.reddit.com/r/VisualStudio/comments/b8vbj8/help_netf461_project_opened_in_vs2019_all_files/

  1. Right click on "References" in the Solution Explorer在解决方案资源管理器中右键单击“参考”
  2. Select "Manage NuGet Packages"选择“管理 NuGet 包”
  3. Under the "Installed" tab search fro "Microsoft.Net.Compilers"在“已安装”选项卡下搜索“Microsoft.Net.Compilers”
  4. Select "Microsoft.Net.Compilers"选择“Microsoft.Net.Compilers”
  5. On the side window of "Microsoft.Net.Compilers" click the update button在“Microsoft.Net.Compilers”的侧面窗口中单击更新按钮

    • VS2015 is compatible with .NET Compiler 1.xx VS2015 兼容 .NET Compiler 1.xx
    • VS2017 is compatible with .NET Compiler 2.xx VS2017 兼容 .NET Compiler 2.xx
    • VS2019 is compatible with .NET Compiler 3.xx VS2019 兼容 .NET Compiler 3.xx

So, just update Microsoft.Net.Compilers according to you vs's version因此,只需根据您的 vs 版本更新 Microsoft.Net.Compilers

在 VS2017 中,我可以通过删除 *.vs 文件夹和 *.user 文件来解决这个问题

我遇到了完全相同的问题,结果发现我的项目中的一些 XAML 文件设置为使用操作“XamlAppDef”构建(即构建为 XAML 工作流),当我将其转回“编译”时,我的项目下拉列表立即从(杂项文件)转到正确的项目。

I had this problem in VS2019 after upgrade from 2017. Clean and rebuild of solution fixed it.从 2017 年升级后,我在 VS2019 中遇到了这个问题。清理和重建解决方案修复了它。

  1. Build -> Batch build -> Select all -> Clean构建 -> 批量构建 -> 全选 -> 清理
  2. Build -> Batch build -> Select all -> Build构建 -> 批量构建 -> 全选 -> 构建

When you add a new file in a project, some times visual studio adds it in your project.csproj in <itemGroup> as <Compile Remove> so that file will not be compiled and will not be copied with the build files.当您在项目中添加新文件时,有时 Visual Studio 会将其添加到<itemGroup>中的 project.csproj 中作为<Compile Remove> ,这样该文件就不会被编译,也不会与构建文件一起复制。 This is usefull for node_module files for example例如,这对于node_module文件很有用

  <ItemGroup>
    <Compile Remove="Controllers\StockController.cs" />
  </ItemGroup>

you only open your *.csproj and delete it from.您只需打开 *.csproj 并将其删除。

I had this issue in VS 2019 Community with a class file and KING's solution of excluding the file and re-adding it didn't work for me.我在 VS 2019 社区中遇到了这个问题,其中包含一个类文件,而 KING 排除该文件并重新添加它的解决方案对我不起作用。 I was able to fix the issue by我能够通过

  • renaming the problematic cs file重命名有问题的cs文件
  • right clicking the project and choosing Add > Class...右键单击项目并选择添加 > 类...
  • adding the new class file with the same name as the old one添加与旧类同名的新类文件
  • copying the contents of the old renamed file and pasting it into the new one, overwriting the default contents复制旧重命名文件的内容并将其粘贴到新文件中,覆盖默认内容
  • deleting the old renamed file删除旧的重命名文件

Due to TypeScript, check that your file matches to pattern, specified in tsconfig.json file in "include" section.由于 TypeScript,请检查您的文件是否与“include”部分的 tsconfig.json 文件中指定的模式匹配。 If .ts file not inculded by tsconfig, then intellicense will show it as Miscellaneous.如果 tsconfig 未包含 .ts 文件,则 intellicense 会将其显示为 Miscellaneous。

After trying all the other offered solution, what worked for me is:在尝试了所有其他提供的解决方案之后,对我有用的是:

  • Editing the .gitattributes file.编辑.gitattributes文件。
  • adding *.xproj text eol=crlf添加*.xproj text eol=crlf

So that my VS2015 xproj style .NET Core/Standard projects worked again.这样我的 VS2015 xproj 风格的 .NET Core/Standard 项目就可以再次工作了。

Turned out that my git was putting UNIX style EOL, which was confusing VS.原来我的git正在放置 UNIX 风格的 EOL,这让 VS 感到困惑。

If it's not showing up in your Solution Explorer, try clicking the "Show All Files" button at the top of Solution Explorer.如果它没有显示在您的解决方案资源管理器中,请尝试单击解决方案资源管理器顶部的“显示所有文件”按钮。 If the files become visible and are located under the project you expect them to be in, but the file still has "Miscellaneous" listed as its project, then right click the files and select "Include in Project".如果文件变得可见并且位于您希望它们所在的项目下,但该文件仍将“杂项”列为其项目,则右键单击文件并选择“包含在项目中”。 Otherwise try dragging them to the proper project.否则尝试将它们拖到正确的项目中。

I just hit this issue in VS 2017 and this is what worked for me.我刚刚在 VS 2017 中遇到了这个问题,这对我有用。

If this is still an issue you might check through your Nuget packages.如果这仍然是一个问题,您可以检查您的 Nuget 包。 By default in VS 2017 some projects would include references to various compiler libraries from Microsoft.默认情况下,在 VS 2017 中,某些项目将包含对 Microsoft 的各种编译器库的引用。 These almost certainly aren't needed.这些几乎可以肯定是不需要的。 In my case removing them immediately resolved the miscellaneous files issue.在我的情况下,删除它们立即解决了杂项文件问题。

I can't recall which Nugets exactly but I am pretty sure one of them was - Microsoft.CodeDom.Providers.DotNetCompilerPlatform我不记得究竟是哪个 Nugets,但我很确定其中一个是 - Microsoft.CodeDom.Providers.DotNetCompilerPlatform

Somehow I solved this by going to properties (Right-click the file and select Properties).不知何故,我通过转到属性(右键单击文件并选择属性)解决了这个问题。 The Build Action was set to Content.构建操作设置为内容。 Just change it to Compile and problem solved.只需将其更改为编译即可解决问题。

perhaps after some refactoring,you have modified the name of the project under TFS and Rename the project using the Solution Explorer (ie right click the project and click rename) which does not match this project name on source Control Explorer.也许经过一些重构,您已经修改了 TFS 下的项目名称,并使用与源代码管理资源管理器上的项目名称不匹配的解决方案资源管理器重命名项目(即右键单击项目并单击重命名)。 in this way you will see "Miscellaneous Files" in the Solution Explorer that are not associated with TFS,The Miscellaneous Files folder represents the files as links.这样,您将在解决方案资源管理器中看到与 TFS 无关的“杂项文件”,杂项文件文件夹将文件表示为链接。 for more detail My Response have been written here有关更多详细信息, 我的回复已写在这里

This Worked for me:这对我有用:

  • Check the namespace is given properly.检查命名空间是否正确。
  • Go to Files > Close solution and then reopen the solution.转到文件 > 关闭解决方案,然后重新打开解决方案。

If you not have compiler package miscellaneous files will created when build solution.如果您没有编译器包,则会在构建解决方案时创建其他文件。 So, Check nuget package Microsoft.Net.Compilers is installed or not.因此,检查 nuget 包 Microsoft.Net.Compilers 是否安装。 Install if not, or do update on that package.如果没有,请安装,或者对该软件包进行更新。 I did this and my issue solved.我这样做了,我的问题解决了。

You might need to increase the Windows filepath length, to allow it greater than 256 characters for filepaths.您可能需要增加 Windows 文件路径长度,以允许文件路径的长度超过 256 个字符。

In my case, the several files were very deep in folders and caused the long filepaths issue.就我而言,这几个文件在文件夹中非常深,并导致了长文件路径问题。 Search online how to increase it (via Registry & regedit).在线搜索如何增加它(通过注册表和注册表编辑器)。 You'll have to restart PC afterwards.之后您必须重新启动PC。

也许你只能在另一个解决方案中打开错误项目,并在新的解决方案中添加你需要的项目

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

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