简体   繁体   English

Visual Studio Code 中没有 C# 代码分析

[英]No C# Code Analysis in Visual Studio Code

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.我目前使用 VS Code 进行 C# 开发,因为我发现它比 Visual Studio 本身轻得多,但似乎没有任何可用的代码分析工具。 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.我已经安装了 Microsoft 的官方 C# 扩展,但它似乎没有帮助。 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.我也无法在 VS Code Marketplace 中找到任何代码分析扩展,而在线搜索只会将我指向 Visual Studio 的扩展。 I am also aware that FxCop can be installed via NuGet, but it seems to only be for Visual Studio as well.我也知道 FxCop 可以通过 NuGet 安装,但它似乎也只适用于 Visual Studio。

Are there any C# code analysis tools that can be used with VS Code?是否有任何可以与 VS Code 一起使用的 C# 代码分析工具? Even external tools or dotnet commands would help.即使是外部工具或 dotnet 命令也会有所帮助。

Special thanks to Martheen for suggesting this link.特别感谢Martheen建议此链接。

All I had to do was add the following to my VS Code settings to enable better code analysis:我所要做的就是将以下内容添加到我的 VS Code 设置中,以便更好地进行代码分析:

"omnisharp.enableRoslynAnalyzers": true // Enable C# code analysis.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM