Menees.Analyzers 4.0.0

Prefix Reserved
dotnet add package Menees.Analyzers --version 4.0.0
                    
NuGet\Install-Package Menees.Analyzers -Version 4.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Menees.Analyzers" Version="4.0.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Menees.Analyzers" Version="4.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Menees.Analyzers">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Menees.Analyzers --version 4.0.0
                    
#r "nuget: Menees.Analyzers, 4.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Menees.Analyzers@4.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Menees.Analyzers&version=4.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Menees.Analyzers&version=4.0.0
                    
Install as a Cake Tool

windows build & test Nuget

Analyzers

This project provides several new C# code analysis rules for projects built with the .NET 10 SDK or later. These rules can be used with other analyzers like .NET's.

This software is CharityWare. If you use it, I ask that you donate something to the charity of your choice.

ID Title Comment
MEN001 Tabs should be used for indentation Ensures tabs are used for indentation instead of spaces. This is the opposite of StyleCop's SA1027: TabsMustNotBeUsed rule. This is similar to the StyleCop+ rule SP2001: CheckAllowedIndentationCharacters when set to "Tabs only".<br><br>This rule is off by default because it conflicts with Visual Studio's default settings, which use spaces instead of tabs for indentation. This rule can be enabled using a custom ruleset file, and it includes a code fix provider.
MEN002 Line is too long Ensures that lines are not longer than 160 characters. This is similar to the StyleCop+ rule SP2100: CodeLineMustNotBeLongerThan. The MaxLineColumns and TabSize values for this rule can be configured in .editorconfig.
MEN002A Line is long Notifies when lines are longer than 160 characters. This rule is off by default because MEN002 takes precedence and is sufficient for most cases. If you enable this rule, then you should also configure NotifyLineColumns to be less than MaxLineColumns in .editorconfig.
MEN003 Method is too long Ensures that methods are not longer than 120 lines. This is similar to the StyleCop+ rule SP2101: MethodMustNotContainMoreLinesThan. The MaxMethodLines limit for this rule can be configured in .editorconfig.
MEN004 Property accessor is too long Ensures that property accessors are not longer than 80 lines. This is similar to the StyleCop+ rule SP2102: PropertyMustNotContainMoreLinesThan. The MaxPropertyAccessorLines limit for this rule can be configured in .editorconfig.
MEN005 File is too long Ensures that files are not longer than 2000 lines. This is similar to the StyleCop+ rule SP2103: FileMustNotContainMoreLinesThan. The MaxFileLines limit for this rule can be configured in .editorconfig.
MEN006 #regions should be used Recommends that #regions be used when there are over 100 lines in a file or if there is more than one class, struct, enum, or interface defined in a file.<br><br>This rule is off by default because it conflicts with StyleCop's SA1124: DoNotUseRegions rule. This rule can be enabled using a custom ruleset file. The MaxUnregionedLines limit for this rule can be configured in .editorconfig.<br><br>Note: Menees VS Tools can be used to easily add, collapse, and expand #regions in C# code (as well as in VB, XML, XAML, HTML, SQL, JavaScript, and TypeScript code).
MEN007 Use a single return Recommends that only a single return statement should be used in a code block. "One entry, one exit" keeps control flow simple and makes refactoring easier.
MEN008 File name should match type Ensures that a file name matches or includes the name of the main type it contains. The TypeFileNameExclusions for this rule can be configured in .editorconfig.
MEN009 Use the preferred exception type Recommends preferred exception types (e.g., NotSupportedException instead of NotImplementedException). This rule is a complement to CA2201, and it includes a code fix provider.
MEN010 Avoid magic numbers Recommends that named constants be used instead of numeric literals (i.e., magic numbers). The AllowedNumericLiterals for this rule can be configured in .editorconfig.
MEN011 Align using directives Ensures that using directives are aligned. This is important when using directives are nested inside a namespace (per SA1200: UsingDirectivesMustBePlacedWithinNamespace) because Visual Studio will often fail to indent them correctly if they're added while code contains syntax errors. This rule includes a code fix provider.
MEN012 Flags should be powers of two Flags enum members should be powers of two or bitwise-or combinations of named members. This rule is a complement to CA2217.
MEN013 Use UTC time Recommends UTC times because they're unambiguous and always increasing. This rule includes a code fix provider.
MEN014 Prefer TryGetValue Recommends calling TryGetValue (for a single lookup and retrieval) instead of ContainsKey and this[key] with duplicate lookups.
MEN015 Use Preferred Terms Similar to the old FxCop CA1726 rule except this rule only checks single terms (not double terms). So it uses a slightly different set of default preferred terms (omitting double terms like LogOn), and it includes Id as a preferred term over ID (per FxCop's CA1709 rule).
MEN016 Avoid Top-Level Statements C# top-level statements are only for toy/example programs and should be avoided in long-term code for consistency and maintainability.
MEN017 Remove Unused Private Setter A private set accessor is not needed when an auto property is only assigned in the constructor. Inspired by C# Essentials' Use Getter-Only Auto-Property.
MEN018 Use Digit Separators Numeric literals should use digit separators ('_' from C# 7) to improve readability. This applies to hexadecimal, binary, and integer or real literals.
MEN019 Async method needs CancellationToken An async method should take a CancellationToken parameter or take a parameter that has a public CancellationToken property. Inspired by this dotnet issue and related to CA2016 and CA1068.
MEN020B Use preferred var style for built-in types Local variable declarations for built-in types (e.g., int, string, bool) should use the preferred var style based on the configured BuiltInTypes rules. This rule includes a code fix provider and is related to IDE0007 and IDE0008.
MEN020S Use preferred var style for simple types Local variable declarations for simple types (non-generic, non-built-in types like Guid, MyClass) should use the preferred var style based on the configured SimpleTypes rules. This rule includes a code fix provider and is related to IDE0007 and IDE0008.
MEN020E Use preferred var style elsewhere Local variable declarations for other types (e.g., generic types like List<int>, Dictionary<string, int>) should use the preferred var style based on the configured Elsewhere rules. This rule includes a code fix provider and is related to IDE0007 and IDE0008.

Configuration

Many of the rule limits and settings can be configured via .editorconfig.

.editorconfig

Add menees_analyzers.* keys to your .editorconfig file:

[*.cs]
menees_analyzers.max_line_columns = 120
menees_analyzers.tab_size = 4
menees_analyzers.allow_long_uri_lines = true
menees_analyzers.preferred_term.Cancelled = Canceled
menees_analyzers.var_style.built_in_types = use_explicit_type
Supported keys
Category Key Type Default
Scalars menees_analyzers.tab_size int 4
menees_analyzers.max_line_columns int 160
menees_analyzers.notify_line_columns int 160
menees_analyzers.max_method_lines int 120
menees_analyzers.max_property_accessor_lines int 80
menees_analyzers.max_file_lines int 2000
menees_analyzers.max_unregioned_lines int 100
menees_analyzers.allow_long_uri_lines bool true
menees_analyzers.allow_long_four_slash_comment_lines bool false
Cancellation menees_analyzers.cancellation.check_private_methods bool false
menees_analyzers.cancellation.check_private_types bool false
menees_analyzers.cancellation.property_names comma-delimited CancellationToken, Cancellation
Digit Separators menees_analyzers.decimal.min_size byte 6
menees_analyzers.decimal.group_size byte 3
menees_analyzers.hexadecimal.min_size byte 8
menees_analyzers.hexadecimal.group_size byte 4
menees_analyzers.binary.min_size byte 8
menees_analyzers.binary.group_size byte 4
Collections menees_analyzers.allowed_numeric_literals comma-delimited 0, 1, 2, 100
menees_analyzers.allowed_numeric_caller_names comma-delimited FromDays, FromHours, ...
menees_analyzers.allowed_numeric_caller_regexes comma-delimited (none)
menees_analyzers.test_class_attributes comma-delimited TestClass, TestFixture
menees_analyzers.test_method_attributes comma-delimited TestMethod, Test, Fact, Theory
File Exclusions menees_analyzers.analyze_file_name_exclusions comma-delimited GeneratedCode.cs
menees_analyzers.analyze_file_regex_exclusions comma-delimited (see source)
menees_analyzers.type_file_name_exclusions comma-delimited Enumerations.cs, Interfaces.cs, Delegates.cs
menees_analyzers.type_file_regex_exclusions comma-delimited (see source)
Preferred Terms menees_analyzers.preferred_term.<Avoid> string (Prefer) (merged with defaults)
Var Style menees_analyzers.var_style.built_in_types use_explicit_type | use_var (none)
menees_analyzers.var_style.simple_types use_explicit_type | use_var (none)
menees_analyzers.var_style.elsewhere use_explicit_type | use_var (none)
Var Conditions menees_analyzers.var_style.<category>.foreach bool
menees_analyzers.var_style.<category>.linq_scalar_result bool
menees_analyzers.var_style.<category>.linq_collection_result bool
menees_analyzers.var_style.<category>.linq_aggregate_result bool
menees_analyzers.var_style.<category>.long_type_name bool
menees_analyzers.var_style.<category>.long_type_name_length int 30
menees_analyzers.var_style.<category>.evident bool

Notes:

  • Comma-delimited collections (e.g., allowed_numeric_literals) replace the defaults entirely when specified.
  • Preferred terms merge with the defaults: .editorconfig terms add to or override the default preferred terms.
  • Var style conditions (foreach, evident, etc.) apply only when the mode is use_var. The <category> placeholder is built_in_types, simple_types, or elsewhere.

Migrating From XML Settings

In version 4.0, support for Menees.Analyzers.Settings.xml was removed. All settings must now be configured via .editorconfig. The following table maps each former XML setting (as an XPath expression) to its .editorconfig counterpart:

XML Setting (XPath) .editorconfig Key
/Menees.Analyzers.Settings/TabSize menees_analyzers.tab_size
/Menees.Analyzers.Settings/MaxLineColumns menees_analyzers.max_line_columns
/Menees.Analyzers.Settings/NotifyLineColumns menees_analyzers.notify_line_columns
/Menees.Analyzers.Settings/MaxMethodLines menees_analyzers.max_method_lines
/Menees.Analyzers.Settings/MaxPropertyAccessorLines menees_analyzers.max_property_accessor_lines
/Menees.Analyzers.Settings/MaxFileLines menees_analyzers.max_file_lines
/Menees.Analyzers.Settings/MaxUnregionedLines menees_analyzers.max_unregioned_lines
/Menees.Analyzers.Settings/AllowLongUriLines menees_analyzers.allow_long_uri_lines
/Menees.Analyzers.Settings/AllowLongFourSlashCommentLines menees_analyzers.allow_long_four_slash_comment_lines
/Menees.Analyzers.Settings/AnalyzeFileNameExclusions/FileName menees_analyzers.analyze_file_name_exclusions (comma-delimited)
/Menees.Analyzers.Settings/AnalyzeFileNameExclusions/FileRegex menees_analyzers.analyze_file_regex_exclusions (comma-delimited)
/Menees.Analyzers.Settings/TypeFileNameExclusions/FileName menees_analyzers.type_file_name_exclusions (comma-delimited)
/Menees.Analyzers.Settings/TypeFileNameExclusions/FileRegex menees_analyzers.type_file_regex_exclusions (comma-delimited)
/Menees.Analyzers.Settings/AllowedNumericLiterals/Literal menees_analyzers.allowed_numeric_literals (comma-delimited)
/Menees.Analyzers.Settings/AllowedNumericLiterals/CallerName menees_analyzers.allowed_numeric_caller_names (comma-delimited)
/Menees.Analyzers.Settings/AllowedNumericLiterals/CallerRegex menees_analyzers.allowed_numeric_caller_regexes (comma-delimited)
/Menees.Analyzers.Settings/UnitTestAttributes/Class menees_analyzers.test_class_attributes (comma-delimited)
/Menees.Analyzers.Settings/UnitTestAttributes/Method menees_analyzers.test_method_attributes (comma-delimited)
/Menees.Analyzers.Settings/PreferredTerms/Term[@Avoid] menees_analyzers.preferred_term.<Avoid> = <Prefer>
/Menees.Analyzers.Settings/DigitSeparators/Decimal/@MinSize menees_analyzers.decimal.min_size
/Menees.Analyzers.Settings/DigitSeparators/Decimal/@GroupSize menees_analyzers.decimal.group_size
/Menees.Analyzers.Settings/DigitSeparators/Hexadecimal/@MinSize menees_analyzers.hexadecimal.min_size
/Menees.Analyzers.Settings/DigitSeparators/Hexadecimal/@GroupSize menees_analyzers.hexadecimal.group_size
/Menees.Analyzers.Settings/DigitSeparators/Binary/@MinSize menees_analyzers.binary.min_size
/Menees.Analyzers.Settings/DigitSeparators/Binary/@GroupSize menees_analyzers.binary.group_size
/Menees.Analyzers.Settings/SupportAsyncCancellationToken/@CheckPrivateMethods menees_analyzers.cancellation.check_private_methods
/Menees.Analyzers.Settings/SupportAsyncCancellationToken/@CheckPrivateTypes menees_analyzers.cancellation.check_private_types
/Menees.Analyzers.Settings/SupportAsyncCancellationToken/Properties/Property menees_analyzers.cancellation.property_names (comma-delimited)
/Menees.Analyzers.Settings/UsePreferredVarStyle/BuiltInTypes menees_analyzers.var_style.built_in_types
/Menees.Analyzers.Settings/UsePreferredVarStyle/SimpleTypes menees_analyzers.var_style.simple_types
/Menees.Analyzers.Settings/UsePreferredVarStyle/Elsewhere menees_analyzers.var_style.elsewhere
UseVar/Foreach menees_analyzers.var_style.<category>.foreach
UseVar/LinqScalarResult menees_analyzers.var_style.<category>.linq_scalar_result
UseVar/LinqCollectionResult menees_analyzers.var_style.<category>.linq_collection_result
UseVar/LinqAggregateResult menees_analyzers.var_style.<category>.linq_aggregate_result
UseVar/LongTypeName menees_analyzers.var_style.<category>.long_type_name
UseVar/LongTypeName/@Length menees_analyzers.var_style.<category>.long_type_name_length
UseVar/Evident menees_analyzers.var_style.<category>.evident
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Menees.Analyzers:

Package Downloads
PixelatedLabs.Standard

Common static analysis configuration for .NET projects.

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Menees.Analyzers:

Repository Stars
TASEmulators/BizHawk
BizHawk is a multi-system emulator written in C#. BizHawk provides nice features for casual gamers such as full screen, and joypad support in addition to full rerecording and debugging tools for all system cores.
planetarium/libplanet
Blockchain in C#/.NET for on-chain, decentralized gaming
Version Downloads Last Updated
4.0.0 52 4/10/2026
3.4.0 71 4/9/2026
3.3.9 94 4/8/2026
3.3.8 96 4/8/2026
3.3.7 165 4/7/2026
3.3.6 135 4/5/2026
3.3.5 4,758 2/24/2026
3.3.4 12,504 11/27/2025
3.3.3 11,207 9/7/2025
3.3.2 901 9/4/2025
3.3.1 455 9/3/2025
3.3.0 450 9/1/2025
3.2.2 209,153 6/5/2024
3.2.1 15,825 5/28/2024
3.2.0 1,765 5/27/2024
3.1.1 88,522 4/11/2024
3.1.0 3,930 3/29/2024
3.0.13 100,630 3/27/2024
3.0.12 36,633 1/14/2024
3.0.11 188,959 5/30/2023
Loading failed