dotgenie.MicrosoftStyleNamingAnalyzer 5.0.0

dotnet add package dotgenie.MicrosoftStyleNamingAnalyzer --version 5.0.0
                    
NuGet\Install-Package dotgenie.MicrosoftStyleNamingAnalyzer -Version 5.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="dotgenie.MicrosoftStyleNamingAnalyzer" Version="5.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="dotgenie.MicrosoftStyleNamingAnalyzer" Version="5.0.0" />
                    
Directory.Packages.props
<PackageReference Include="dotgenie.MicrosoftStyleNamingAnalyzer">
  <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 dotgenie.MicrosoftStyleNamingAnalyzer --version 5.0.0
                    
#r "nuget: dotgenie.MicrosoftStyleNamingAnalyzer, 5.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 dotgenie.MicrosoftStyleNamingAnalyzer@5.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=dotgenie.MicrosoftStyleNamingAnalyzer&version=5.0.0
                    
Install as a Cake Addin
#tool nuget:?package=dotgenie.MicrosoftStyleNamingAnalyzer&version=5.0.0
                    
Install as a Cake Tool

Microsoft Style Naming Analyzer

NuGet Version Downloads

A comprehensive Roslyn analyzer that enforces Microsoft naming conventions for C# code. Automatically detects naming violations and provides intelligent correction suggestions with red squiggles in Visual Studio and VS Code.

🎯 Features

Comprehensive Naming Convention Enforcement

  • Classes & Interfaces: PascalCase with proper I-prefix for interfaces
  • Methods & Properties: PascalCase
  • Variables, Fields & Parameters: camelCase
  • Hungarian Notation Detection: Automatically suggests removing prefixes like str, int, bln

Smart Corrections

  • Converts snake_case to PascalCase or camelCase as appropriate
  • Removes Hungarian notation prefixes (strUserName → UserName)
  • Adds interface I-prefix when missing (UserService → IUserService)
  • Provides exact correction suggestions in warning messages

🚀 Quick Start

Installation

dotnet add package dotgenie.MicrosoftStyleNamingAnalyzer

Usage

Once installed, the analyzer automatically runs during build and provides warnings for naming violations:

// ❌ Violations detected:
public class user_service    // MSN001: Should be 'UserService'
{
    public string user_name { get; set; }  // MSN004: Should be 'UserName'
    private int strAge;                    // MSN008: Should be 'age' (Hungarian removal + camelCase)
    
    public void get_user_data(string User_ID)  // MSN003 + MSN007: Method and parameter violations
    {
        string Local_Variable = "";  // MSN006: Should be 'localVariable'
    }
}

// ✅ Corrected code:
public class UserService
{
    public string UserName { get; set; }
    private int age;
    
    public void GetUserData(string userID)
    {
        string localVariable = "";
    }
}

📋 Diagnostic Rules

Rule ID Description Example
MSN001 Class names must be PascalCase user_class → UserClass
MSN002 Interface names must start with 'I' and be PascalCase userService → IUserService
MSN003 Method names must be PascalCase get_data() → GetData()
MSN004 Property names must be PascalCase user_name → UserName
MSN005 Field names must be camelCase User_Field → userField
MSN006 Variable names must be camelCase Local_Var → localVar
MSN007 Parameter names must be camelCase Input_Data → inputData
MSN008 Remove Hungarian notation strUserName → UserName

🔧 Configuration

The analyzer works out-of-the-box with default Microsoft naming conventions. All rules are enabled by default and provide warnings (not errors) to maintain build compatibility.

Supported Hungarian Prefixes

  • str (string) → removed
  • int, lng (integer) → removed
  • flt, dbl, dec (decimal) → removed
  • bln, bool (boolean) → removed
  • obj (object) → removed
  • arr, lst (array/list) → removed
  • dic (dictionary) → removed

🎯 Why Use This Analyzer?

✅ Benefits

  • Consistent Code Style: Enforces Microsoft naming conventions across your entire codebase
  • Developer Productivity: Instant feedback with red squiggles and correction suggestions
  • Code Quality: Improves readability and maintainability
  • Team Alignment: Ensures all developers follow the same naming standards
  • Legacy Code Cleanup: Identifies and suggests fixes for outdated Hungarian notation

🏢 Perfect For

  • Enterprise applications requiring consistent naming
  • Teams transitioning from other naming conventions
  • Legacy codebases with Hungarian notation
  • Open source projects following Microsoft guidelines
  • Code reviews and quality gates

🛠️ Requirements

  • .NET Standard 2.0 or higher
  • Visual Studio 2019+ or VS Code with C# extension
  • Roslyn Analyzers support

📝 Example Output

When you build your project, you'll see helpful warnings like:

warning MSN001: Class 'user_manager' should be 'UserManager' (PascalCase required)
warning MSN004: Property 'user_id' should be 'UserId' (PascalCase required)  
warning MSN008: Remove Hungarian notation: 'strFirstName' should be 'FirstName'

🤝 Contributing

Found an issue or want to contribute? This analyzer is part of the DotGenie toolkit for improving C# code quality.

📄 License

MIT License - See LICENSE file for details.


Made with ❤️ by DotGenie - Helping developers write better C# code, one naming convention at a time.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.0 217 10/24/2025
1.1.0 208 10/24/2025
1.0.0 197 10/24/2025