How to identify unused methods, codes, libraries and references in VScode

493 views Asked by At

Team,

I need to identify & remove unused variables (arguments, local variables, class member variables), Libraries, and references that are unused in VS code.

I have also tried to find out some extensions or plugins or Nuget packages but no luck and also researched a lot but didn't find relevant links which can fulfill my need. I know someone from this community who can help me with this.

Please check below code sample for unused code and I want something to identify that are unused and want to remove those.

using System;
using System.Diagnostics; //unused
using Microsoft.AspNetCore.Mvc; //unused
using Microsoft.AspNetCore.Mvc.RazorPages; //unused

public class HelloWorld
{
    public string? RequestId { get; set; } //unused 
    private readonly ILogger<ErrorModel> _logger; //unused
    public static void Main(string[] args)
    {
        Console.WriteLine ("Hello Mono World");
    }
    public ErrorModel(ILogger<ErrorModel> logger) // This method is unused
    {
       //Some code here
    }

}
1

There are 1 answers

0
John Briggs On

Using the C# Dev Kit for VSCode extension, it seems it doesn't highlight some non-primitive cases within Tasks, even if the function only returns a Task.

In the example, all primitive unused foos are detected, however anotherTest instances are not detected as unused withing the ReturnTaskTest().

code example where returning a Task from a function results in no unused object warning