Skip to content

Latest commit

ย 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
DevCase VB.NET Code Analysis logo

DevCase VB.NET Code Analysis

Roslyn analyzers and code fixes for Visual Basic .NET, packaged as a Visual Studio extension.

Visual Studio Marketplace: Download Extension


Forksย  Contributorsย  Followersย  Watchers Sponsorsย  Stars

Latest Release Language Visual Studio License
Repo size Total Downloads Last commit Pull Requests Open IssuesClosed Issues Maintenance

Made in Spain


๐Ÿ‘‹ Introduction

DevCase VB.NET Code Analysis is a set of Roslyn diagnostic rules for Visual Basic .NET, most of them with an automatic code fix (Visual Studio lightbulb action). It finds and repairs problems that the built-in .NET analyzers do not cover for VB.NET: deadlock-prone Await expressions, silent guard clauses, missing or incomplete XML documentation, recursion, file-system loops that freeze the message pump, regular expressions without a ReDoS timeout, ambiguous dates, and much more.

Several rules are VB.NET equivalents of SonarQube rules, with an automatic fix that respects the semantics of the original code. Each rule document lists any overlap with Microsoft's built-in analyzers.

The whole project, analyzers, code fixes and tests included, is written in VB.NET with Option Strict On, Option Explicit On and Option Infer Off.

๐Ÿ’ก Motivation

Over the years, I have established a rigorous custom coding standard for my VB.NET libraries: fail-fast argument validation, ConfigureAwait(False) on virtually every Await, comprehensive XML documentation covering absolutely every public and private member, mandating iterative methods over recursion, bit-shifted <Flags> enums to prevent manual integer calculation mistakes, explicit Option directives, etc. To enforce this discipline, I developed offline VisualBasicSyntaxRewriter snippets that I run across my codebases.

Although functional, that offline methodology is a tedious and time-consuming chore relegated to post-coding manual reviews, lacking any semantic context. DevCase VB.NET Code Analysis turns that standard into live diagnostics that show up while typing, with one-click fixes, and with semantic precision instead of text heuristics.

โšก The Real Question

Why keep fixing the same mistakes by hand when the compiler platform can point at them, and fix them, as you type?

๐Ÿค– Features

  • A comprehensive set of diagnostic rules, most of them featuring a code fix, all fixes supporting Fix All (document, project and solution). Rules without a safe, behavior-preserving fix only report.
  • Semantic precision: rules bind symbols through the Roslyn semantic model, so look-alike names (myAsyncSettings.Result) are not reported and no fix produces code that does not compile.
  • .NET Framework migration helpers: dedicated rules prepare .NET Framework code for modern .NET by adding #If NETCOREAPP blocks with the recommended modern APIs, keeping the original code untouched in the #Else branch.
  • Behavior first: when a fix offers several actions, the first one keeps the current behavior and only makes it explicit (for example DateTimeKind.Unspecified or CultureInfo.CurrentCulture); fixes that could change the result are never applied silently.
  • Respectful fixes: preserve comments, trivia, region layout, line endings (CRLF/LF) and indentation; never reformat unrelated code.
  • Configurable through .editorconfig (custom options and standard severity overrides).
  • Visual Studio 2022 and 2026 (amd64 and arm64) from a single VSIX.

๐Ÿ“‹ Rules

ID Rule Severity Category Code fix
DCA001 โณ Missing ConfigureAwait(False) Error Reliability โœ”๏ธ
DCA002 ๐Ÿงฑ Blocking .Result on a task Error Reliability โœ”๏ธ
DCA003 ๐Ÿคซ Silent guard clause Error Reliability โœ”๏ธ
DCA004 ๐Ÿ“œ Missing Option statements Warning Style โœ”๏ธ
DCA005 ๐Ÿ—๏ธ Missing explicit constructor Warning Design โœ”๏ธ
DCA006 ๐Ÿ“ฆ Type in the global namespace Warning Design โœ”๏ธ
DCA007 ๐Ÿ“ Public member without XML documentation Warning Documentation โœ”๏ธ
DCA008 ๐Ÿงพ <param> tags do not match the parameters Warning Documentation โœ”๏ธ
DCA009 ๐Ÿ”ค String comparison argument omitted Warning Globalization โœ”๏ธ (ร—2)
DCA010 ๐Ÿšฉ <Flags> enum member without bit-shift syntax (disabled by default) Warning Style โœ”๏ธ
DCA011 ๐Ÿ” Argument guards with a modern throw-helper equivalent (.NET Framework) Info Portability โœ”๏ธ
DCA012 ๐Ÿ’ฅ Thrown exception is not documented Warning Documentation โœ”๏ธ
DCA013 ๐Ÿš€ .NET Framework API with a modern .NET equivalent (.NET Framework) Info Portability โœ”๏ธ
DCA014 ๐Ÿ—‚๏ธ File-system loop without Thread.CurrentThread.Join(0) Warning Reliability โœ”๏ธ
DCA015 ๐Ÿ”„ Method calls itself (recursion) Warning Design โŒ
DCA016 โšก Async Sub that is not an event handler Warning Reliability โœ”๏ธ
DCA017 โฑ๏ธ Regular expression without match timeout Error Security โœ”๏ธ
DCA018 ๐Ÿ•’ DateTime created without DateTimeKind Warning Reliability โœ”๏ธ
DCA019 ๐ŸŒ Date or time parsed without a format provider Warning Globalization โœ”๏ธ
DCA020 ๐Ÿšฉ <Flags> enumeration without a None zero value Warning Design โœ”๏ธ
DCA021 ๐Ÿ” LINQ method instead of Find / Exists / TrueForAll Warning Performance โœ”๏ธ
DCA022 ๐ŸŽฏ LINQ method instead of the indexer Warning Performance โœ”๏ธ
DCA023 ๐Ÿ”„ Negated comparison Warning Style โœ”๏ธ
DCA024 ๐Ÿ” Catch block that only rethrows Warning Design โœ”๏ธ
DCA025 ๐Ÿงน Redundant null check before TypeOf Warning Style โœ”๏ธ
DCA026 ๐Ÿ”ค Text encoding not specified Warning Globalization โœ”๏ธ
DCA027 ๐Ÿ’ค Thread.Sleep in an Async method Warning Reliability โœ”๏ธ
DCA028 ๐Ÿงต Windows Forms entry point without <STAThread> Warning Reliability โœ”๏ธ
DCA029 โž• String concatenated with + Warning Style โœ”๏ธ
DCA030 ๐Ÿ“ฆ Array creation expression can be an array literal Info Style โœ”๏ธ
DCA031 ๐Ÿท๏ธ Array designator on the variable name Info Style โœ”๏ธ
DCA032 ๐Ÿ›‘ End statement Warning Reliability โŒ
DCA033 ๐Ÿšง On Error statement Warning Reliability โŒ
DCA034 โ†ช๏ธ GoTo statement Info Design โŒ
DCA035 ๐ŸŒ€ Application.DoEvents inside a loop Warning Reliability โŒ
DCA036 ๐Ÿ” SyncLock on a publicly accessible or weak-identity object Warning Reliability โŒ
DCA037 ๐Ÿ”“ Monitor.Enter without Monitor.Exit in a Finally block Warning Reliability โŒ
DCA038 โธ๏ธ Thread.Suspend or Thread.Resume Warning Reliability โŒ
DCA039 ๐Ÿ“ฎ Delegate BeginInvoke without EndInvoke Warning Reliability โŒ
DCA040 ๐Ÿ‘ฏ Duplicated condition in If/ElseIf or Select Case Warning Reliability โŒ
DCA041 ๐Ÿชž All branches of a conditional structure are identical Warning Reliability โŒ
DCA042 ๐Ÿงฌ Two branches of a conditional structure are identical Info Design โŒ
DCA043 ๐ŸŸฐ Identical expressions on both sides of a binary operator Warning Reliability โŒ
DCA044 โฒ๏ธ DateTime.Now used to measure elapsed time Info Reliability โŒ
DCA045 ๐Ÿ—ƒ๏ธ Path.GetTempFileName creates a predictable temporary file Warning Security โœ”๏ธ
DCA046 ๐Ÿงจ Exception thrown in a Finally block Warning Reliability โŒ
DCA047 โ˜ ๏ธ Exception thrown in Finalize Warning Reliability โŒ
DCA048 ๐Ÿซณ Exception thrown in a property getter Info Design โŒ
DCA049 ๐Ÿ”ค Single-character string where a Char can be used Info Performance โœ”๏ธ
DCA050 ๐Ÿ›‚ Parameter of an externally visible method is not validated Info Design โœ”๏ธ
DCA051 ๐Ÿ•ณ๏ธ Awaiter or ConfigureAwait result discarded Warning Reliability โŒ
DCA052 ๐Ÿ“› Parameter named sender outside an event handler Info Naming โœ”๏ธ
DCA053 ๐Ÿซ™ Method call without parentheses Info Style โœ”๏ธ

Click a rule to see its purpose, detection details, edge cases and VB.NET code examples.


๐Ÿ“ Requirements

  • Visual Studio 2026 (18.x) or Visual Studio 2022 (17.8 or later), on Windows.
  • The rules analyze Visual Basic projects that target any framework: .NET Framework, .NET Standard or modern .NET.

๐Ÿš€ Getting Started

Option A: Install the VSIX (recommended)

  1. Navigate to the Releases page.
  2. Download DevCase.CodeAnalysis.Vsix.vsix.
  3. Close Visual Studio and double-click the .vsix file to install it.

Option B: Build from source

  1. Open DevCase.CodeAnalysis.sln in Visual Studio (workload: Visual Studio extension development).

  2. Select the Release configuration and build DevCase.CodeAnalysis.Vsix, or run this command from the Developer PowerShell for VS:

    msbuild src\DevCase.CodeAnalysis.Vsix\DevCase.CodeAnalysis.Vsix.vbproj /restore /p:Configuration=Release
  3. The package is generated at src\DevCase.CodeAnalysis.Vsix\bin\Release\net472\DevCase.CodeAnalysis.Vsix.vsix.

To debug the analyzers, set DevCase.CodeAnalysis.Vsix as the startup project and press F5: an experimental instance of Visual Studio starts with the extension loaded.

Note

Analyzers installed through a VSIX run inside the IDE (live analysis, Error List and lightbulb), not on command-line builds. Info-level rules (DCA011, DCA013, DCA030, DCA031, DCA034, DCA042, DCA044, DCA048, DCA049, DCA050, DCA052, DCA053) appear in the Messages tab of the Error List and as gray dots under the code.

โš™๏ธ Configuration

All the options are set in an .editorconfig file (or a global analyzer configuration file):

[*.vb]
# DCA010 (disabled by default because of legacy P/Invoke flag enums).
devcase_analyzers.dca010_enabled = true

# DCA001 code fix: emit ConfigureAwait(continueOnCapturedContext:=False).
devcase_analyzers.configure_await_named_argument = true

# DCA006 code fix: namespace used to wrap types declared in the global namespace.
# When not set: the namespace already declared in the file, or else the assembly name.
devcase_analyzers.default_namespace = Contoso.Tools

# DCA011 code fix: conditional compilation symbol of the throw-helper branch.
devcase_analyzers.dca011_condition = NET8_0_OR_GREATER

# DCA017 code fix: match timeout in milliseconds (default: 30000).
devcase_analyzers.dca017_timeout_ms = 30000

# Standard Roslyn severity overrides.
dotnet_diagnostic.DCA007.severity = suggestion
dotnet_diagnostic.DCA015.severity = none

๐Ÿ”• Disabling rules

Every rule document has a How to disable section with ready-to-copy examples. In short:

# .editorconfig: one rule, or a whole category, for a solution, project or folder.
[*.vb]
dotnet_diagnostic.DCA022.severity = none
dotnet_analyzer_diagnostic.category-Performance.severity = suggestion
' A few lines of code.
#Disable Warning DCA024 ' Reason.
' ...
#Enable Warning DCA024
' A type or member (category and "ID:Title" as shown in each rule document).
<System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "DCA024:Catch block only rethrows the exception", Justification:="Reason.")>

๐Ÿงช Quality

The test project (xUnit v3) builds in-memory VB.NET projects and:

  • checks the exact spans of every expected diagnostic;
  • applies every code fix repeatedly, re-parsing the text between passes like the IDE does, and verifies that the fixed code still compiles;
  • verifies Fix All batch merging;
  • runs every analyzer, code fix and Fix All test twice, with LF and CRLF line endings, and checks that the fixes never mix line endings (the Roslyn formatter writes the line ending of the operating system);
  • compiles the .NET Framework rules against the real .NET Framework 4.8 reference assemblies, and the modern branch of their fixes against .NET;
  • enforces every DCA rule on its own code at build time: the CodeFixes and Tests projects reference the analyzers as analyzers, the Analyzers project is checked by a self-analysis test, and Visual Studio's code style suggestions are raised to warnings in the repository .editorconfig, so the solution builds with 0 warnings;
  • verifies that every suppression mechanism documented in the rules (.editorconfig, #Disable Warning, SuppressMessage) works;
  • runs all the analyzers on their own source code (dogfooding) and checks that the code base contains no recursion.
dotnet test tests/DevCase.CodeAnalysis.Tests

๐Ÿ›๏ธ Solution layout

src/DevCase.CodeAnalysis.Analyzers   netstandard2.0   Diagnostic analyzers and shared detection logic
src/DevCase.CodeAnalysis.CodeFixes   netstandard2.0   Code fix providers
src/DevCase.CodeAnalysis.Vsix        net472           VSIX container (VS 2022 + VS 2026, amd64 + arm64)
tests/DevCase.CodeAnalysis.Tests     net10.0          xUnit v3 tests

๐Ÿ”„ Change Log

Explore the complete list of changes, bug fixes, and improvements across different releases by clicking here.

๐Ÿ’ช Contributing

Your contribution is highly appreciated!. If you have any ideas, suggestions, or encounter issues, feel free to open an issue by clicking here.

Your input helps make this Work better for everyone. Thank you for your support! ๐Ÿš€

๐Ÿ’ฐ Beyond Contribution

This work is distributed for educational purposes and without any profit motive. However, if you find value in my efforts and wish to support and motivate my ongoing work, you may consider contributing financially through the following options:

Platform How to Support
Become my sponsor on GitHub
Contribute any amount you prefer and unlock rewards!
Support me on Ko-fi
Buy me a coffee!
Become a Patron on Patreon
Support my open-source work regularly!
Make a PayPal Donation
Donate any amount you like via PayPal!
Purchase my software at Envato's CodeCanyon
Discover my desktop tools and DevCase Class Library for .NET, an extensive API suite.

Your support means the world to me! Thank you for considering it! ๐Ÿค—๐Ÿ’—

๐Ÿ† Credits

This work relies on the following technologies, libraries or resources:

โš ๏ธ Disclaimer

This software and its associated repository are provided strictly on an "as is" basis, without warranties of any kind, whether express or implied. This includes, but is not limited to, any implied warranties of merchantability, reliability, or fitness for a particular purpose.

The authors and copyright holders assume no liability for any direct, indirect, incidental, or consequential damagesโ€”including data loss or system errorsโ€”arising from the use, misuse, or inability to use this software. You are solely responsible for determining the appropriateness of using this tool and assume all associated risks.

Code fixes modify source code: review the changes they make and keep your code under version control.

Furthermore, this project operates entirely independently. The utilization of any third-party libraries or components within this software does not imply any affiliation with, or endorsement or approval by, their respective original authors.

By using this software, you agree to indemnify and hold harmless the authors from any claims, damages, or liabilities arising from your use or misuse of it.

This project is licensed under the Apache License, Version 2.0. See the License file for details.

Releases

Sponsor this project

Packages

Contributors

Languages