Visual Studio Marketplace: Download Extension
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.
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.
Why keep fixing the same mistakes by hand when the compiler platform can point at them, and fix them, as you type?
- 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 NETCOREAPPblocks with the recommended modern APIs, keeping the original code untouched in the#Elsebranch. - Modern code-quality rules for .NET Framework: .NET Framework projects miss many of the built-in rules of modern .NET (CA1826, CA1827, CA1829, CA1854, CA1861, CA2016, CA2263, WFO1000...). Rules marked (.NET Framework) replicate them, with a VB.NET code fix where Microsoft has one, and stay silent on modern .NET, where the original rule runs.
- Behavior first: when a fix offers several actions, the first one keeps the current behavior and only makes it explicit (for example
DateTimeKind.UnspecifiedorCultureInfo.CurrentCulture); fixes that could change the result are never applied silently. - Scannable messages: every message follows the same pattern, what to do + where + why (optional), in one short sentence ("Concatenate strings using '&' instead of '+' to avoid operator ambiguity"), so a long Error List can be read at a glance.
- 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.
Click a rule to see its purpose, detection details, edge cases and VB.NET code examples.
Rules marked (.NET Framework) run only in .NET Framework projects: on modern .NET, Microsoft's built-in rules report the same code (for example CA1050 for DCA006, CA1825 for DCA055, CA1861 for DCA084), so nothing is reported twice. DCA055, DCA056, DCA058 and DCA059โDCA084 bring to .NET Framework the code-quality rules that Microsoft only ships for modern .NET (and WFO1000, the Windows Forms designer rule of .NET 9); each rule document names the rule that it replicates.
Severity says how serious the reported code is, not how much it is worth changing:
| Severity | Meaning | Rules |
|---|---|---|
| Error | Code that the compiler accepts but that can never work. | DCA054 |
| Warning | Code that can fail at run time, hang, lose exceptions or data, or that hides a defect (unreachable or duplicated code). | DCA001, DCA002, DCA004, DCA014โDCA017, DCA020, DCA024, DCA027โDCA029, DCA032, DCA035โDCA043, DCA045โDCA047, DCA051, DCA060โDCA066, DCA069, DCA070 |
| Info | Style, structure, documentation, naming, readability and micro-performance: the code works, the fix makes it clearer or faster. | The rest |
Using an API as the .NET class library exposes it (for example Task.Result) is never an Error: it compiles and works. Every severity can be changed in .editorconfig (dotnet_diagnostic.DCA009.severity = warning).
The RuleTesting folder contains a solution, DCA Rule Testing Project.slnx, with two Visual Basic projects:
| Project | Target | Files |
|---|---|---|
DCA Rule Testing (net 48) |
.NET Framework 4.8 | DCA001.vb โฆ DCA084.vb: one file per rule |
DCA Rule Testing (net 10) |
.NET 10 (net10.0-windows) |
One file per rule, except the rules that run only on .NET Framework (DCA006, DCA011, DCA013, DCA046, DCA055, DCA056, DCA058, DCA059โDCA084) |
Each DCAnnn.vb file triggers only the rule of its name, and its XML documentation says what is reported and what the code fix writes. To try them:
- Install the extension (see Getting Started).
- Open
DCA Rule Testing Project.slnxin Visual Studio, and open the Error List (Ctrl+\,E) with Build + IntelliSense selected. Info-level rules are in the Messages tab. - Open a file, for example
DCA052.vb, and set the filter of the Error List to Current Document: it shows only DCA052. Place the cursor on the reported code and pressCtrl+.to preview and apply the code fix.
A few details of the solution:
- Its
.editorconfigenables DCA010, which is disabled by default. - The projects are applications, not class libraries, because the
Endstatement ofDCA032.vbis not allowed in class libraries.Program.vbis the entry point and triggers no rule. - The My Project files of the .NET Framework project (
AssemblyInfo.vb,Application.Designer.vb,Resources.Designer.vb,Settings.Designer.vb) show the excluded files: no rule reports them. - A test of the solution compiles both projects as Visual Studio does and checks that every file reports its rule and nothing else, so the files stay in sync with the rules. Another test applies every code fix to these files and checks that the result compiles and keeps its
#Regionand#Ifdirectives.
- 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.
- Navigate to the Releases page.
- Download
DevCase.CodeAnalysis.Vsix.vsix. - Close Visual Studio and double-click the
.vsixfile to install it.
-
Open
DevCase.CodeAnalysis.slnin Visual Studio (workload: Visual Studio extension development). -
Select the
Releaseconfiguration and buildDevCase.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
-
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 (DCA003, DCA005, DCA006, DCA007, DCA008, DCA009, DCA010, DCA011, DCA012, DCA013, DCA018, DCA019, DCA021, DCA022, DCA023, DCA025, DCA026, DCA030, DCA031, DCA033, DCA034, DCA044, DCA048, DCA049, DCA050, DCA052, DCA053, DCA055, DCA056, DCA057, DCA058, DCA059, DCA067, DCA068, DCA071โDCA084) appear in the Messages tab of the Error List and as gray dots under the code.
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 = noneThe rules never analyze generated files, project metadata files or suppression files. A file is excluded when its name ends with one of these patterns, immediately followed by its extension (.vb, .cs...), in any letter case:
| Pattern | Examples |
|---|---|
.Designer |
Form1.Designer.vb, Resources.Designer.vb, Settings.Designer.vb |
.AssemblyAttributes |
.NETFramework,Version=v4.8.AssemblyAttributes.vb |
AssemblyInfo |
AssemblyInfo.vb, MyApp.AssemblyInfo.vb (generated by SDK projects) |
GlobalSuppressions |
GlobalSuppressions.vb, GlobalSuppressions.cs |
.g, .g.i |
MainWindow.g.vb, App.g.i.vb (WPF) |
.generated |
Reference.generated.vb |
Files whose name starts with TemporaryGeneratedFile_ (temporary files of the WPF build), files that start with an <auto-generated> comment header (such as Reference.vb of service references) and files marked with generated_code = true in .editorconfig are excluded as well. Form1.vb, Designer.vb or AssemblyInfoReader.vb are analyzed: the pattern must be a suffix of the name.
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.")>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);
- runs every analyzer and code fix test again on six syntax variations of its source, the same code written in another way: redundant parentheses,
_line continuations, method bodies inside#Region,#If True ThenandUsingblocks, and comment lines between statements. Each variation must report the same diagnostics, and its fix must still compile and leave no diagnostic, so a rule that only recognizes one way of writing the code fails its existing tests, without writing the variations by hand; - 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;
- compiles the two projects of the rule testing solution as Visual Studio does, and checks that every
DCAnnn.vbfile reports its rule and no other; - applies every code fix (each of its actions, with Fix All in Document) to those
DCAnnn.vbfiles, as they are and decorated with preprocessor directives around every type, member and statement (complete and enclosing#Regionblocks,#If True Thenblocks, disabled#If False Thencode), and checks that the project still compiles without warnings, that no preprocessor directive is lost (except those inside the body of a member that the fix removes), and that#Region/#End Regionstay balanced.
dotnet test tests/DevCase.CodeAnalysis.Testssrc/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
The RuleTesting folder, at the root of the repository, holds the rule testing solution (one file per rule, for .NET Framework 4.8 and .NET 10). It is not part of DevCase.CodeAnalysis.sln: its projects need the extension installed in Visual Studio.
Explore the complete list of changes, bug fixes, and improvements across different releases by clicking here.
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! ๐
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. |
This work relies on the following technologies, libraries or resources:
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.