What’s New for Visual Basic in Visual Studio 2022

Kathleen Dollard

Visual Studio 2022 and .NET 6.0 have some great new features for Visual Basic developers. Some of these features can affect the way you write code every day. Many of the productivity features covered here are available to you whether you program for .NET Framework or for the latest version of .NET.

Overall

Visual Studio 2022 has a new look, with the new Cascadia font and updated icons. If you have customized your font, you may need to explicitly set your font to Cascadia. You have several Cascadia choices with different weights and two styles: Mono and Code. Cascadia Mono is the default. Choose Cascadia Code if you would like ligatures. Ligatures express two or more characters as a single unit. For Visual Basic, this mainly affects the appearance of >=, <= and <>. Cascadia Code with ligatures looks like:

Cascadia Code font showing ligatures

And with Cascadia Mono, you get the more traditional look:

Cascadia Mon font with no ligatures

You can change your font in Tools > Options > Environment > Fonts and Colors.

For folks that like a dark theme, Visual Studio 2022 updates its dark theme with new colors that reduce eyestrain, improve accessibility, and provide consistency with the Windows dark theme. You can change your theme in Tools > Options > Environment > General. You can set your theme to match your Windows theme by selecting “Use system settings.”

Visual Studio now runs as a 64-bit process, with better performance for many operations and better handling of very large solutions. Since it’s now a 64 bit process, you may need to update extensions or MSBuild tasks.

Debugging

Visual Studio has several great variations of breakpoints. In Visual Studio 2022, as you move your cursor within the left margin, a dot will show up. Click it to find available types of breakpoints:

Left margin right click popup

When you select a breakpoint type that needs more information, the breakpoint settings dialog will appear in-line in your code:

Breakpoint settings dialog

I setup several breakpoint variations to show the glyphs for different kinds of breakpoints:

Code with several breakpoint variations, What’s New for Visual Basic in Visual Studio 2022

The breakpoint showing the clock symbol is a temporary breakpoint. As soon as it is hit, it will disappear. This is great if you want your application to run until you get to a certain spot, and then you have other exploration to do. The solid circle is a normal breakpoint, and the plus inside a circle indicates a conditional breakpoint.

The last glyph with the arrow is the most powerful. It represents a new kind of breakpoint – the dependent breakpoint. This breakpoint is hit if, and only if, another breakpoint is hit. I set a condition for the breakpoint on line 7 to x = 5. Since that breakpoint is not hit, the breakpoint on line 8 is not hit. I plan to use this when I want to stop at the first iteration of a loop, but only if an outer condition is met. Previously, I needed to enable one breakpoint until the outer condition was met, and only after that was hit enable a breakpoint inside the loop.

A tracepoint is like a breakpoint, but it continues execution. Use this to display a message in the output window. When you select a tracepoint, the breakpoint settings dialog opens and hovering over the information icon has great help:

Tracepoint output help popup, What’s New for Visual Basic in Visual Studio 2022

Tracepoints have been around for a while and Visual Studio 2022 makes them easier to setup.

You can combine many types of breakpoints, like the very powerful conditional tracepoints. Note that some combinations, like dependent tracepoints aren’t legal and you’ll see an error at the top of the dialog.

If you realize a breakpoint or a tracepoint is not on the correct line after you set it up, in Visual Studio 2022 you can just move it by dragging and dropping. Any conditions or breakpoint dependencies are maintained. Of course, if you move it outside the context of the condition, you will get errors notifying you of this. You can also use Ctrl-Z to reset a breakpoint you accidentally delete.

Sometimes you have breakpoints set up, but for now you want to skip all of them to get to your current location in code. You can do that in Visual Studio 2022 by right clicking the line you want to stop at and selecting “Force run to cursor”. This will act like “Run to cursor”, but bypass any breakpoints encountered along the way.

Editor

A number of new features in the editor make your everyday coding smoother and more efficient.

Subword navigation

You probably use Ctrl-Left and Ctrl-Right to move one word to the left and right. In Visual Studio 2022, you can use Ctrl-Alt-Left and Ctrl-Alt-Right to move left and right by parts of words:

Animation of subword navigation

This supports the Pascal style of symbol naming.

Inheritance Margin

The inheritance margin adds icons to the left margin representing where code is derived from other code, and where other code derives from this code. The icon is marked here with an arrow:

Code with left martin inheritance icons, What’s New for Visual Basic in Visual Studio 2022

If you click on one of these icons, a popup will display the base or derived classes or methods:

Right click on inheritance icon with popup

You can click on the popup entries to quickly navigate to the base or derived class or method.

You can enable or disable this feature in Tools > Options > Text Editor > Basic > Advanced and deselect Enable Inheritance Margin.

Underline reassigned

The new underline reassigned feature is for folks that want to know whether variables are reassigned, or remain set to their initial value. Any variables that are reassigned will look like:

Code with reassigned code underlined

This is turned off by default. If you want hints to where data changes are happening, turn it on in Tools > Options > Text Editor > Basic > Advanced.

IntelliSense for preprocessor symbols

Preprocessor symbols now have IntelliSense. The available symbols will appear after you type #If:

Code with IntelliSense for If directive

Inline parameter name hints

Another optional feature is parameter name hints. When turned on it displays a small indicator for the parameter name:

Code showing parameter name hint

You can enable or disable this feature in Tools > Options > Text Editor > Basic > Advanced. This is disabled by default.

Add missing Imports on paste

Visual Studio 2022 will add required namespace imports when you paste a code block which contains a code element requires a namespace import:

Animation of pasting code and import appears

You can enable or disable this feature in Tools > Options > Text Editor > Basic > Advanced.

Edited here: A previous version included the “Inline diagnostics” feature here in error. This feature is part of the 17.1 (Visual Studio 2022 Update 1) preview, not 17.0 (Visual Studio 2022).

Refactoring

Several new refactorings help you write more correct and efficient code.

Simplify LINQ expression

Passing a predicate to a LINQ method like Any is more efficient than first calling Where and then calling Any. You can position the cursor in a LINQ expression and hit “Ctrl .” to determine if the expression can be simplified. For example:

Refactoring popup showing predicate moved to Any, What’s New for Visual Basic in Visual Studio 2022

Change methods to Shared

Shared methods do not rely on data within the instance of the class. You can identify the methods in your classes that could be Shared, and update them with the “Make static” refactoring. The use of the C# keyword static instead of Shared will be updated in an upcoming version of Visual Studio.

Refactoring popup showing addition of Shared keyword, What’s New for Visual Basic in Visual Studio 2022

The Generate Overrides dialog appears when you type “Ctrl .”, you are in a class that has overridable methods, and you select “Generate Overrides.” With a large number of potential overrides, it can be troublesome to pick out the item you want to override. The Generate Overrides dialog now offers a text box so you to filter to the overridable methods you’re interested in:

Generate overrides dialog with arrow to new search textbox, What’s New for Visual Basic in Visual Studio 2022

WinForms startup

The Visual Basic Application Model provides the familiar Visual Basic experience for application startup, particularly for WinForms and WPF applications. This model has been updated in .NET 6.0 to support a new event: ApplyApplicationDefaults. This event lets you set application wide values that must be set before any forms or controls are created. These values are:

  • Font: The global font for the application. The default font changed for .NET to provide an updated experience. This font is often desirable, but can cause issues where pixel perfect layout was done with the traditional .NET Framework font. (See the section Known issues)
  • MinimumSplashScreenDisplayTime: The minimum time for the splash screen to be displayed.
  • HighDpiMode: WinForms applications can respond to the High DPI characteristics of the monitor where the application is being run. This happens via the default value HighDpiMode.SystemAware. If you need the .NET Framework behavior, use HighDpiMode.DpiUnaware.

To set these values, first open the file ApplicationEvents.vb:

Solution Explorer with pointer ApplicationDefaults.vb, What’s New for Visual Basic in Visual Studio 2022

Then select “(MyApplication events)” in the middle combobox at the top of the edit window (marked with an arrow below). When this is selected, you’ll be able to select “ApplyApplicationDefaults” from the right combobox:

Editor showing Sub MyApplication_ApplyApplicationDefaults, What’s New for Visual Basic in Visual Studio 2022

This will create the method and when you set values you set on the ApplyApplicationDefaultsEventArgs parameter, those values will be applied to your application before the first forms are created.

The common defaults will work for most applications and you will not need to specify anything for those applications.

Support for C# init properties

C# introduced a feature called init properties which indicate that a property is immutable after the constructor completes. In Visual Basic 16.9, we added support for the following scenario:

  • A C# project/assembly has a class that includes an init property
  • A Visual Basic project has a class that inherits from this class
  • The Visual Basic class sets the init property in its constructor

In Visual Basic 16 and below, this causes a compiler error. Starting in Visual Basic 16.9, you may set init properties in inherited Visual Basic constructors. If you need this feature, set the language version to latest or 16.9.

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <RootNamespace>ConsoleApp1</RootNamespace>
    <TargetFramework>net6.0</TargetFramework>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>

Roslyn Source Generators

Roslyn Source Generators let you generate code at design time. We added this feature to Visual Basic earlier this year. You can find out more about Roslyn Source Generators in this article.

Hot Reload

Hot Reload builds on Edit and Continue technology. Instead of stopping at a breakpoint and then changing your code, just change your code and hit the Hot Reload button. For example, if you want to change the logic that runs on a button click – change your code and hit Hot Reload. The next time you click the button, your new logic will run – no breakpoints needed.

One of the cool things about Hot Reload is that it works wherever Edit and Continue work, both .NET and .NET Framework.

Hot Reload is a core technology that covers many scenarios, however there are some edits that are not supported at this time. For example, if you move a WinForms control or change something in Properties, that change won’t currently appear in Hot Reload for C# or Visual Basic. Also, if you add a control or other object that uses WithEvents to a Visual Basic application, you will receive a message that that you’ve made an unsupported change.

Hot Reload will cover more scenarios as it evolves in upcoming releases. Try it out with your applications to simplify the way you interact with Edit and Continue.

Upgrade your Visual Basic apps to .NET 6.0

If you are happy using .NET Framework, you can continue to use it with confidence. .NET Framework 4.8 is the latest version of .NET Framework and will continue to be distributed with future releases of Windows..

Many of the great features in this post apply to both .NET Framework and .NET.

If you want the new features we are introducing in the common libraries and supported workloads, you can move to .NET 6.0.

To explore upgrading, check out the Upgrade Assistant which now supports Visual Basic and is out of preview and generally available.

As part of your transition, you can also target .NET Standard 2.0 to share code between .NET Framework and .NET, as well as between C# and Visual Basic.

Known issues

“Remove unused references” is present in the Solution Explorer right click dialog. While it can be used to remove project references, in at least some cases unused package references are not recognized.

The new .editorconfig dialog contains features for all languages, and many of the settings are specific to C#. This is because .editorconfig is often used at the root of a solution that contains multiple languages. We are working to improve how to include the language where settings are language specific.

Regarding WinForms fonts: The Visual Basic project (.vbproj) IntelliSense includes <ApplicationDefaultFont>. This is intended to determine the design time font for the WinForms designer. As mentioned in the WinForms startup section above, the font used when your application runs is the Font property you assign to the ApplyApplicationDefaults event argument in MyApplication (in ApplicationEvents.vb). Setting these both to the same font is intended to set the same font for design time and application runtime. However, the <ApplicationDefaultFont> in .vbproj is currently ignored. The WinForms team is working on this issue.

In closing

As you can see here, the experience of Visual Basic just keeps getting better. We’ve enabled many new features in Visual Studio 2022 and we’re excited for you to download the new release and give it a try on your Visual Basic solutions.

31 comments

Discussion is closed. Login to edit/delete existing comments.

  • hitesh davey 1

    VS2022 is a product of hard work indeed. Good Job VS Team!

    It has been a very long time since a blog from MS about VB.NET. It always feels good to read a blog on VB.NET especially when it is about “What’s new for VB”. It is so unfortunate that this beautiful computer programming language is not going forward to see any more feature updates. In my view, If language like PYTHON can succeed then there is no reason why VB.NET cannot surpass it. Btw, after reading the blog I realized there is nothing new in VB.net per se. 🙂

    • Cory Smith 0

      Btw, after reading the blog I realized there is nothing new in VB.net per se.

      “Be like a duck. Calm on the surface, but always paddling like the dickens underneath.” — Michael Caine

      I think it’s important to point out that there are actually several “new things” in the language, it’s just that they have been done underneath and not at the surface. Change for changes sake isn’t a good thing. If something can be improved without having to change how we do it, doesn’t it make sense to not introduce something new? A while back there was a big push to add new keywords/structures to VB to handle casting floating point variables/values to whole numbers (Integers, Longs, etc.). This conversation took place over a course of 8+ years… I know because I was involved in those conversations. However, my stance in these conversations was that it wasn’t necessary to change the language; I believed that this was something that we already had in place and it should be done with “compiler optimizations” leveraging what people are already doing. This, in the end, is what was done.

      Fast forward to today… the ability to support init properties in is another example of language change without actually changing the language. And, the section above regarding support for Roslyn Source Generators is a very small blurb… but this is indeed a very BIG DEAL. Furthermore, I think it is VERY IMPORTANT to keep in mind that the support added in .NET 5/.NET 6 for WinForms SPECIFICALLY for VB is another huge accomplishment – and I can verify from the outside (not affiliated with Microsoft) that the WinForms VB-specific stuff was not without it’s trials-and-tribulations in order to accomplish. The Visual Basic Application Model is something that is specific to VB and something that, in all honesty, could have been deprecated (“dropped”) in the transition from .NET Framework to .NET 5+; but it wasn’t… and this is very “new in VB.net per se.”

      If you follow the Roslyn and/or WinForms repo on Github, you’ll find that there are changes being made all the time “under the water”… it’s just on the surface things are pretty calm.

      • Cristian Luis Teixeira 0

        @Cory Smith, thanks so much for the explanation, and I’m really happy that VB continues to evolve, this is definitely great news for all of us who love VB.

      • Taofeek Lasisi 0

        There’re a lot that can be added to VB.NET to get it closer to C# and thus improve programmer productivity. For instance, “pattern matching” is one. In C# one could do something like:

        Assuming a generic type contains the following method, where T is a TypedDataRow.

        public T ConvertToTypedRow(object obj){
        if (obj is DatarowView vw){
        if (vw.row is T result){
        return result;
        }
        }
        return null;
        }

        Then from another class, you can call the function:

        var shRow = ConvertToTypedRow(bindingsource.current);

        Or in VB, it can be called as:
        Dim shRow = ConvertToTypedRow( Of SalesHeaderRow )(bindingsource.current)

        Another area, and related to pattern matching above is the Case statement in VB as compared to the improvements since C# 7.1/C#7.2, reducing amount of code and improving readability.

    • Muhammad Miftah 0

      In my view, If language like PYTHON can succeed then there is no reason why VB.NET cannot surpass it.

      It seems you’re not really familiar with Python, if you think that. Python is so much more concise than VB.NET in almost every regard, to the point it’s basically executable pseudo-code. And despite .NET Core being cross platform, everyone associates VB.NET with being a Windows-only language.

  • Chris Conti 0

    Am I the only one who thinks ligatures in source code are the next tabs vs spaces? I’ve tried it a couple of times, but it just feels like the uncanny valley of code when I look at the screen.

    From the description above, it sounds like they are disabled by default, but they do seem to be creeping into many other coding and text tools recently…

    • Immo LandwerthMicrosoft employee 0

      Since ligatures are a rendering only concern and not persisted in the code, it’s more like dark theme vs light discussion, not tabs vs spaces.

  • VVit1 Smarty 0

    The new default font named ‘Cascadia’ looks good with my home plus ultra HiDpi monitor.
    But with standard monitor my eyes are bleeding from this font.

    • Kathleen DollardMicrosoft employee 0

      I had to experiment with the weight for Cascadia to get it happy on my different monitors. It has a bunch of different weights (how thick the letters are).

    • Pavel Chmelar 0

      Yes, Cascadia font looks good, but the Consolas font is better for Full HD resolution in my opinion. It’s more sharper and consuming less space even if the font’s size is same. The most important is that with the Consolas we see more lines than the Cascadia.

  • Richard Kinning 1

    This is good stuff. I was worried a few years back about MS announcement about VB. If MS keeps VB working on the latest .net versions and allowing it to access new .net features as they come out is a very good thing. I feel much better about VB after seeing it work with .net 6.0.

    Off to install VS2022, until now I had no reason to go there.

    Thank you!

    • Cory Smith 1

      There are many reasons to make the leap to .NET 6! As someone who has been working with the first versions of .NET Core into .NET 6; I can say that it has certainly been “on the bleeding edge” with regards to VB. Even with the existing limitations (along the way), I’ve found scenarios that were interesting enough to get me engaged very early in on this road. Today is very different and I’m very happy to share that VB has come a very, very, very long way on the road from these first versions .NET Core to today.

      I, for one, am all in on VB and .NET 6! Now that you have a reason “to go there”, welcome! I also encourage you to check out https://gitter.im/VB-NET/community

  • Alexander Wurzinger 0

    “Remove unused references” is present in the Solution Explorer right click dialog.
    This seems to be a C# feature.
    I remember, many version ago, VS had this feature for VB.Net in the Project Settings, References ‘Tab’.
    Is there any plan to bring this feature back to VB.Net?

  • josh miller 0

    If you just bring over Linq2SQL Visual Basic/.net6 , you will gain a huge audience outside of the c# world (even though it’s not really competeing)
    Linq2SQL very much promoted RAD which was always the point of Visual Basic going 25 years back even, so keep going with it!

    • Jens Samson 0

      Without bringing over L2S to .Net 6 or an official migration path (and EF getting a lot better) we’re stuck in the .Net framework 4.8.
      Sad.

    • Flash BFE 0

      +1
      I use Linq2SQL every day and it is used widely it seems. What is the reason to pull over bad old Windows Forms to .NET6 but not more modern technologies that are simple and efficient?

  • Dominique Gratpain 0

    Hello,

    More 20 years ago, Microsoft Basic PDS 7.1 used conditional breakpoints. Now VB.Net uses that.
    But also now, VB is the poor parent of .Net. Everything goes for C# and the new F#.

    Bill Gates, when he sold DotNet said that all we can do in VB must to be do in C# and inverse. I (and many developers) liked that. Now it is finished. Microsoft betrayed these words.

    Why ?
    – the gravity center of software development is in Asia (money is money) and people don’t know VB
    – young people learned Java at University (Java is free) then Microsoft pushes C# which is a Java clone

    I don’t agree with you, Katleen, when you wrote : “As you can see here, the experience of Visual Basic just keeps getting better. “.
    It will be true if VB implements all news inside C#. It is not the case, you put a single coat of paint.

    C# is now at the version 10, F# at the version 6, what is the new version of VB ?

    Best regards,

    • Markus Zoschke 0

      Under the F# post, there are almost no reactions. It is a nerd language, which is upheld by MSFT for the coolness factor, while VB is still big in the not-so-cool business world.

      I wonder, if MSFT simply added a compiler switch to C#, removing the need for all those unneeded, ugly curly braces, some minor tweaks to camel casing keywords, naming the result B# (I know, that ship has sailed), if the result would not be better for the community and the platform as a whole. Code would almost exactly look like Python.

      But then, XML literals are a major feature in VB, as well as all the legacy goodness C# is only getting at. Many IDE features have a much more mature feel in VB than in C#. Having done some live coding with an audience, you I seldomly mistype in VB, while C# behaves like a crooked witch.

      I’m cool with MSFT don’t turning VB into a feature hodgepodge like C#. That said, we need some minor language improvements, and I think adding the ability to level the extensions story and the ability to add operators would be high on my list.

      But then, the platform has other problems than adding vanity features to languages. No true generic 2D graphics model, no generic interface to describe, what an image is (so that we can connect libs without hardcoding for Skia or ImageSharp), no PDF support, no SVG support. You simply cannot leave this to the community, while Java has all this Apache Foundation stuff. (Possibly, we should just be able to load PDFbox into a .NET process?)

      Aw yes, and ASP.NET is really good. But it is also slowly coming back full circle. If you compare minimal API with .ashx-code, there is very little difference, if you used DI patterns on the latter.

      Yes, platform independence is valuable and cherished. Same goes for the huge performance increases. I still wonder, if the path chosen to get to this point was the best, ie most efficient and lenient way to achieve it.

  • SuperCocoLoco . 0

    Why this post is not in the Language->Visual Basic blog?

    • hitesh davey 0

      Becoz It is about what’s new FOR VB in VS2022.
      There is nothing new in VB to write an exclusive blog about WHAT’S NEW IN VB language.
      We shouldn’t be surprised if we don’t see any new posts in the VB blog section hereafter. It is done and dusted with one simple sentence…”Going forward, we do not plan to evolve Visual Basic as a language!” -MS

  • Leo Cheung 1

    I start my programming life since VB6 on 1998, and start .NET Dev since ASP.NET 1.1.
    Had been use VB.NET until .NET 3.5.

    Back to early of 2000, I still remember many peoples hype about C# is Java-Bracket syntax and (What Java can do and C# can do it too),
    and also some wrong statement said C# is more powerful than VB.NET, at that time, many programmer obsolete VB syntax and said using Keywords – Dim, As, If-End If, End While …. are ridiculous, because it is not so (Java), but today Python, Ruby are just VB-like syntax and success.

    IMO, VB is soul of Visual Studio and iconic of MS Programming.

    • Cristian Luis Teixeira 1

      At the first opportunity, the market demonstrated that it does not prefer “C” languages, despite {}; also be used by Javascript, it’s a much simpler dialect than Java.
      For me, the DEV world is well defined and will be dominated by Python, JavaScript and Java, the difference from developers who use Python, JS and Java is much bigger than C # the difference gets to be monstrous.

      It is sad to see that MS missed the mark in their strategy.

      Maybe if MS had modernized VB.NET and even VBA could compete with Python, but now this is very difficult to happen, this new generation has eyes only for Python and JS, today MS languages ​​are not the first choice for new developers.

      MS products also generate a lot of confusion, they are not good at creating new names, which makes the search confusing.

      There is also the problem with the documentation that the code is mostly in C#, converting C# code to VB and F# is not a transparent and respectful attitude towards the VB and F# developer.

      I’ll be using VB as much as possible because it’s my favorite language, but I’m already focusing more on JS and its entire ecosystem.

      as MS has a philosophy of creating and eliminating technologies every 12 months, this time I will not continue with MS, I have already had several losses in the name of a trust that was not fulfilled.

      After VB.net, C# was not my choice

      What I really want is that in the near future VB can act in web and mobile development, for me the VB world is big enough and it cannot be left out of these technologies.

      While that doesn’t happen, I have to use other languages ​​and tools to serve my clients.

      • Silvan Kurth 1

        Well said and I share your opinion 100%.

        • Cristian Luis Teixeira 0

          thanks

      • Cory Smith 1

        Regarding your comment on “modernized VB.NET” … “compete with Python” I assume you are referring to “Top Level Code” features that make it easier to get started with VB (removing the ceremony / boilerplate). I agree with this… if there’s any feature that screams it should be in VB it’s this. I’m working on a project that will hopefully bridge this gap – the (very rough) prototype I’ve have thus far is promising… doesn’t require changes to the compiler and offers some possibility of taking “Top Level Code” to some very interesting (at least to me) levels. (Keep in mind that it’s a spare time project, so not sure how quickly it will be at a level that would be consumable by others.) Feel free to reach out to me on github or twitter (DualBrain) if you have interest in following along (or possibly contributing). I’ll add that I’m also working on enhancements to implementing interfaces and some support for “Records”.

  • Brian Coverstone 0

    If only Microsoft would add optional ref’s into C#, we would be able to convert our VB code to C#.
    The only other option would be tuple destructuring where you can pull out just the variables you want and ignore the rest.
    Either that, or I need to write a program that will create overloads of a single function containing a cartesian product of all possible optional parameter combinations.

    VB is still the king when it comes to needing optional information from a function. Every other language allows it to some extent except C#.

    • Pete Wilson 0

      Apparently you aren’t familiar with C#?

      var (a,_) = (1,2); // assign a=1 the hard way

      While I think an out parameter and an overload can pretty much replace an Optional ByRef, I also think that is a very questionable construct in VB.

Feedback usabilla icon