45

This is a weird one. I have a C# Class Library project within my solution. If I open a .cs file within this project, the Project drop-down on the code editor shows that it belongs to 'Miscellaneous Files'.

Screenshot of the problem

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.

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).

Assembly info is blank

I have tried:

  • Combing through the .csproj file and comparing to others in the solution (no joy)
  • Re-creating the .csproj file and overwriting the old one (worked until I merged the branch into trunk, then the problem re-appeared)
  • Banging my head on the keyboard (headache)

Google has turned up nothing. Does anyone have any ideas as to what's going on here?

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Keith Williams
  • 2,257
  • 3
  • 19
  • 29

20 Answers20

46

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.
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
KING
  • 938
  • 8
  • 26
  • 2
    +1 I had this issue in Visual Studio 2015. After first searching for why all my references were `0` in CodeLens, I noticed the "Miscellaneous Files", leading me here. You can do this for multiple files by commenting them out of the .csproj file, reloading the project, then unloading again to uncomment the lines and bring the files back into the project. –  Jun 20 '16 at 18:10
  • 1
    this works in vs 2017, just exclude and again include without close vs – Ali Yousefi Dec 02 '17 at 08:43
  • 2
    For the googler's trying to figure out how to fix intellisense errors, this is the solution! – Chris Feb 06 '18 at 15:54
26

I have this issue in VS 2017 also.
I found that this miscellaneous files are files added outside the 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.

As workaround I close VS, remove folder .vs from disk and run VS again. After VS will fully initialized these new files are parsed successfully. Note this way clears you custom settings like StartUp Project and so on.

Gendolph
  • 463
  • 7
  • 12
  • Removing .vs files helped me. However, I am unaware of its side effects... – Eray Tuncer Nov 16 '17 at 10:41
  • 2
    You can also try unloading and reloading the project that contains the file instead, which worked for me at least once now. Also notice that I didn't have this problems a few weeks ago, so someone must have introduced this bug just recently, and hence it might be fixed soon. – causa prima Dec 04 '17 at 07:23
  • same, this article here https://developercommunity.visualstudio.com/t/vs-2019-file-is-opened-under-miscellaneous-files-e/487985 supports this. Worked for me i'm using VS2022 community. – ken lacoste Dec 16 '22 at 17:21
13

Here is the Solution:

  • Go to Tools menu > Options > (expand) Environment > Documents (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.
Community
  • 1
  • 1
Xindaar
  • 131
  • 1
  • 2
13

Check that link 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"
  3. Under the "Installed" tab search fro "Microsoft.Net.Compilers"
  4. Select "Microsoft.Net.Compilers"
  5. On the side window of "Microsoft.Net.Compilers" click the update button

    • VS2015 is compatible with .NET Compiler 1.x.x
    • VS2017 is compatible with .NET Compiler 2.x.x
    • VS2019 is compatible with .NET Compiler 3.x.x

So, just update Microsoft.Net.Compilers according to you vs's version

Maksym Manziuk
  • 151
  • 1
  • 5
  • Just add the same problem : from a project created under VS2017 and opened with VS2019, all new created objects (class, interface ...) was set as 'Miscellaneous files'. Upgrading to last 3.x.x version did the trick for me. Thanks – Cladoo Sep 30 '21 at 12:26
  • Worked for me. I'm using VS2019 and VS2022. – ken lacoste Dec 16 '22 at 17:37
9

In VS2017, I was able to fix this issue by deleting *.vs folder and *.user files

Chandra Rana
  • 91
  • 1
  • 2
  • same, this article here https://developercommunity.visualstudio.com/t/vs-2019-file-is-opened-under-miscellaneous-files-e/487985 supports this. Worked for me i'm using VS2022 community. – ken lacoste Dec 16 '22 at 17:20
4

I had exactly the same problem and it turned out that some of the XAML files in my project were set to be built using the action 'XamlAppDef' (ie build it as a XAML Workflow) and when I turned it back to 'Compile', my Project dropdown instantly went from (Miscellaneous files) to the correct project.

JJP
  • 1,439
  • 17
  • 21
3

I had this problem in VS2019 after upgrade from 2017. Clean and rebuild of solution fixed it.

  1. Build -> Batch build -> Select all -> Clean
  2. Build -> Batch build -> Select all -> Build
1

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. This is usefull for node_module files for example

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

you only open your *.csproj and delete it from.

Wajdi Chamakhi
  • 426
  • 5
  • 16
1

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. I was able to fix the issue by

  • renaming the problematic cs file
  • 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
MarnBeast
  • 403
  • 4
  • 10
0

Due to TypeScript, check that your file matches to pattern, specified in tsconfig.json file in "include" section. If .ts file not inculded by tsconfig, then intellicense will show it as Miscellaneous.

Pavel
  • 2,602
  • 1
  • 27
  • 34
0

After trying all the other offered solution, what worked for me is:

  • Editing the .gitattributes file.
  • adding *.xproj text eol=crlf

So that my VS2015 xproj style .NET Core/Standard projects worked again.

Turned out that my git was putting UNIX style EOL, which was confusing VS.

Jesse Chisholm
  • 3,857
  • 1
  • 35
  • 29
0

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.

0

If this is still an issue you might check through your Nuget packages. By default in VS 2017 some projects would include references to various compiler libraries from 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

0

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.

0

perhaps after some refactoring,you have modified the name of the project under TFS and Rename the project using the Solution Explorer (i.e. right click the project and click rename) which does not match this project name on source Control Explorer. 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. for more detail My Response have been written here

0

This Worked for me:

  • Check the namespace is given properly.
  • Go to Files > Close solution and then reopen the solution.
D S
  • 258
  • 9
  • 25
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 03 '21 at 22:51
0

If you not have compiler package miscellaneous files will created when build solution. So, Check nuget package Microsoft.Net.Compilers is installed or not. Install if not, or do update on that package. I did this and my issue solved.

0

You might need to increase the Windows filepath length, to allow it greater than 256 characters for filepaths.

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.

Kari
  • 1,244
  • 1
  • 13
  • 27
0

I've had this problem and it was a user error. Turns out I had multiple copies of the code on my machine and was running a version under project2 while having project1 open in VS. So the debugger worked but loaded version under project2 and confused the heck out of me.

TLDR; Make sure the version running is from the same folders/files you have open in VS.

Morgeth888
  • 143
  • 2
  • 13
-1

maybe you can only open the error project in another solution and add the project you need in the new solution

我零0七
  • 315
  • 3
  • 6