WARNING: I have posted this on Reddit a few weeks ago but never got a response.
I have obtained a large .NET solution from a third-party, and I'm having the following issues with it:
- Right click > Go to Definition for a symbol imported from a namespace defined either in a
PackageReference
orProjectReference
results in the following popup:
- Right click > Find all references for a symbol belonging to a referenced namespace (DLL, project or NuGet package) yields no results, only the following information message in the "Find References" pane
- Intellisense does not work for symbols belonging to referenced namespaces. They are simply not highlighted:
All the above features work fine for symbols defined in the System namespace or the current namespace. Other solutions on my local machine do not exhibit this behavior and work fine. Things I have tried:
- Setting Tools > Options > TextEditor > C# > Advanced > Run background code analysis for to Entire Solution as well as
- Enabling CodeLens
- Deleting the
.vs
folder - Cleaning and Rebuilding, both of which succeed but don't fix the issues I've described above.
None of these things have worked, so I'm beginning to think something more fundamental is going wrong with this particular solution. I can't for the life of me figure out what's wrong with it. What could cause symbols to not get recognized for a solution in Visual Studio 2022? How can I further isolate the root cause of the problem?
I finally figured it out. Here's how:
ConsoleApp1
ClassLibrary1
containing one class calledClass1
ClassLibrary1
fromConsoleApp1
, and added code inProgram.Main
referencingClass1
Class1
symbol inConsoleApp1
was not highlighted and not navigable, similar to my real use case.I then started deleting stuff from the original solution. I thought it might take forever, considering the size of the codebase and the sheer amount of stuff it contains. First I deleted
Directory.Build.props
,Class1
was still not navigable, though my dummy build was fine. TheDirectory.Build.props
file also imports aDirectory.Build.targets
file, so I deleted that as well. Lo and behold,Class1
lit up in green and became navigable. So then I restoredDirectory.Build.targets
, andClass1
was no longer navigable, and I started deleting various property and item groups fromDirectory.Build.targets
until I identified the offending lines:It turns out that, because most of the other developers on the project use Resharper, they want to turn off Roslyn at design time because Resharper has it's own analyzer. Since I prefer not to use Resharper, I had disabled it for this particular solution.
There's an article which says more about this configuration option.