Enable and Use CodeLens in Visual Studio 2022 for .NET Projects
Learn how to turn on CodeLens in Visual Studio 2022, use its inline reference and test‑status icons for quick navigation, and verify the feature works in a .NET solution.
18 Dec 2025, 13:46 UTC

Desired outcome
Enable the CodeLens feature in Visual Studio 2022 so that reference counts, recent changes, and unit‑test status appear inline above code members, allowing quick navigation and insight without leaving the editor.
Necessary prerequisites
- Visual Studio 2022 (Community, Professional, or Enterprise) installed.
- A solution that targets a supported .NET version (.NET Core, .NET Framework, or ASP.NET).
- Sufficient permissions to modify IDE options (no admin rights required).
Focused procedure
- Open the Options dialog: From the main menu choose
Tools → Options. - Navigate to CodeLens settings: Expand
Text Editor → C# → CodeLens. - Enable the feature: Check the box labeled
Enable CodeLensand clickOK. - Load a .NET project: Open a solution or create a new console app (
dotnet new console) to see CodeLens in action. - Observe CodeLens icons: Above each method, property, or class you should see small inline icons showing reference counts, a clock for recent changes, and a test tube for unit‑test status.
- Navigate using CodeLens: Click the reference count icon (e.g., "3 References") to open a peek window that lists all usages; select an entry to jump directly to that location.
- Verify unit‑test status: After building the solution, the test tube icon next to a test method will show "Passed" or "Failed". Run tests via
Test → Run All Teststo see the status update.
Expected checks
- CodeLens icons are visible above code members after enabling the feature.
- Clicking a reference count opens a navigation list without opening a separate file tab.
- Unit‑test status changes after a test run and reflects the latest build.
Recovery options (rollback)
If CodeLens causes noticeable slowdown or memory pressure, you can disable it:
- Return to
Tools → Options → Text Editor → C# → CodeLens. - Uncheck
Enable CodeLensand clickOK. - Restart Visual Studio if the IDE feels unresponsive; the setting persists across sessions.
Limitations and practical verification
CodeLens is disabled by default for legacy project formats (e.g., older .csproj files without SDK‑style). In very large solutions the feature may increase startup time and memory usage; monitoring the IDE’s performance via Help → About Microsoft Visual Studio → Copy Product Information can help you decide whether to keep it enabled.
To verify that CodeLens is active for your specific project, open the Output window, select CodeLens from the dropdown, and look for messages such as "CodeLens service started" when the solution loads.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.