在 Rider 中针对特定项目抑制警告

问题描述 投票:0回答:1

我正在开发一个仅包含模型的项目,并且我有很多像这样的属性:

public string FromReversed
{
    get
    {
        return From.ReverseString();
    }
    #if MyDirective
    [Obsolte("Only in here because if the setter is not included the this property will not be saved into mongoDB")
    set { }
    #endif
}

使用 Rider IDE 时,我收到此警告:

'value' parameter is not used
我可以通过将此注释
// ReSharper disable once ValueParameterNotUsed
放在该属性顶部或将此注释
// ReSharper disable ValueParameterNotUsed
放在我的文件顶部来禁用该警告。 现在我的问题是如何禁用整个项目的警告?

我尝试了这 4 件事,但没有成功:

  1. 如果我这样做

    '.' + Enter
    ,然后将该警告的严重程度从警告更改为“不显示”: 这样做会使警告消失,但我希望该警告也出现在其他项目中。我只是想忽略这个特定项目的警告,而不必去每个文件和地方
    // ReSharper disable ValueParameterNotUsed

  2. 我尝试将此属性放在我的 GlobalUsing.cs 文件中:

global using Swashbuckle.AspNetCore.Annotations;
global using JetBrains.Annotations;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

// This works if I place this attribute on top of the class
[assembly: SuppressMessage("ReSharper", "ValueParameterNotUsed")]
  1. 我尝试根据本文

    https://dunnhq.com/posts/2020/codeinspections/
    resharper_value_parameter_not_used=none
    线放在.editorconfig上。但我可能错误地命名了该属性。

  2. 我尝试放置该警告的 id,因为它在我的 .csproj 文件的标签上不包含数字,如下所示:

<PropertyGroup>
  <NoWarn>1701;1702;ValueParameterNotUsed</NoWarn>
</PropertyGroup>
c# suppress-warnings jetbrains-rider
1个回答
0
投票

您也许可以在

AssemblyAttrubute
中使用
.csproj
定义来实现此目的:

<ItemGroup>
  <AssemblyAttribute Include="System.Diagnostics.CodeAnalysis.SuppressMessage">
    <_Parameter1>ReSharper</_Parameter1>
    <_Parameter2>ValueParameterNotUsed</_Parameter2>
  </AssemblyAttribute>
</ItemGroup>
© www.soinside.com 2019 - 2024. All rights reserved.