MassTransit.Analyzers没有发现潜在的问题

问题描述

我有一个引用Masstransit.Analyzers v7.0.3的ASP.NET Core 3.1 Web API项目,在我的消息使用者中,我具有以下代码,但分析器未发现任何问题。我尝试在匿名对象中添加随机属性,但得到的结果相同。没有错误或警告。

public async Task Consume(ConsumeContext<IGetUser> context)
{
    await context.RespondAsync<IGetUserResponse>(new
    {
    });
}
public interface IGetUserResponse
{
    string FirstName { get; }

    string LastName { get; }

    string UserName { get; }
}

编辑:

这是我在项目中拥有的分析仪的列表。

enter image description here

解决方法

事实证明,如果要使用其中带有stylecop.ruleset的Directory.Build.props,则必须在其中指定MassTransit规则,以便它可以识别代码中的潜在问题。

我在下面添加了几行,现在如果我在响应中错过了一个物业,我会收到警告。

    <Rules AnalyzerId="MassTransit.Analyzers" RuleNamespace="MassTransit.Analyzers">
        <Rule Id="MCA0001" Action="Error" />
        <Rule Id="MCA0002" Action="Error" />
        <Rule Id="MCA0003" Action="Warning" />
        <Rule Id="MTA0001" Action="Warning" />
    </Rules>