CBA0002

Cake method aliases need to be marked with either a CakeMethodAlias or a CakePropertyAlias to be correctly identified and imported by the cake runner

Cause

An alias method is available, but have not been marked with a CakeMethodAlias or a CakePropertyAlias.

Rule Description

A violation of this rule occurs when there is a method with the first parameter that matches (this ICakeContext) is available, but have not yet been marked as an alias by using either CakeMethodAlias or a CakePropertyAlias attribute. One of these attributes is required to be used for Cake to correctly identify and import alias methods.

How to fix violations

To fix a violation of this rule, ensure that there is a CakeMethodAlias or a CakePropertyAlias being used on each method that uses this ICakeContext as their first parameter. A code fix is provided using the light bulb to make this easier.

How to suppress violations

Unless there is a false positive, this rule should NOT be suppressed, but in case of false positive, it can be suppressed in the following ways.

Changing severity using .editorconfig

The severity (and thus suppression) can be changed by using the editorconfig file by using:

[*.cs]
# CBA0002: Missing attribute to mark method as an alias.
dotnet_diagnostic.CBA0002.severity = none

Suppress in project file

You can suppress the warning by using the <NoWarn> element in the csproj project file.

<NoWarn>$(NoWarn);CBA0002</NoWarn>

NOTE: You may have to open and close the solution for the changes to take effect.

Suppressing in code

The violation can be suppressed in code using an attribute (either on class, or global)

[SuppressMessage("Usage",
                 "CBA0002:Missing attribute to mark method as an alias.",
                 Justification = "False Positive")]

Or by using pragma

#pragma warning disable CBA0002 // Missing attribute to mark method as an alias.
#pragma warning restore CBA0002 // Missing attribute to mark method as an alias.
GitHub