I'm currently using VS Code for C# development because I find it to be much more lightweight than Visual Studio itself, but there doesn't seem to be any code analysis tools available. This is a problem as I am not getting any warnings about unused functions (I am able to get warnings about unused local variables, however).
Some sample code:
namespace MyProject
{
// No warning for this unused class.
public class Dog
{
private int _age;
private string _name;
// No warning for this unused field.
private string _furColor;
public Dog(int age, string name)
{
// This unused variable generates a warning as expected.
int unusedVariable = 2;
_age = age;
_name = name;
}
// No warning for this unused private function.
private int Age()
{
return _age;
}
// No warning for this unused public function.
public string Name()
{
return _name;
}
}
}
I already have the official C# extension by Microsoft installed, but it doesn't seem to help. I can't find any code analysis extensions in the VS Code Marketplace either, and searching online only points me to extensions for Visual Studio. I am also aware that FxCop can be installed via NuGet, but it seems to only be for Visual Studio as well.
Are there any C# code analysis tools that can be used with VS Code? Even external tools or dotnet commands would help.
Special thanks to Martheen for suggesting this link.
All I had to do was add the following to my VS Code settings to enable better code analysis:
"omnisharp.enableRoslynAnalyzers": true // Enable C# code analysis.
This might be obvious, but I actually screwed it up: You have to "enable" VS Code inside of your Unity Project https://vionixstudio.com/2021/11/02/unity-visual-studio-code/
If you click on a script this should open VS Code and the code completion should work (at least as long as everything else is set up, worked for me)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With