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:
And with Cascadia Mono, you get the more traditional look:
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:
When you select a breakpoint type that needs more information, the breakpoint settings dialog will appear in-line in your code:
I setup several breakpoint variations to show the glyphs for different kinds of breakpoints:
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:
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:
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:
If you click on one of these icons, a popup will display the base or derived classes or methods:
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:
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
:
Inline parameter name hints
Another optional feature is parameter name hints. When turned on it displays a small indicator for the parameter name:
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:
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:
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.
Generate Overrides dialog supports search
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:
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 valueHighDpiMode.SystemAware
. If you need the .NET Framework behavior, useHighDpiMode.DpiUnaware
.
To set these values, first open the file ApplicationEvents.vb:
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:
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.
If Visual Basic support ASP.NET Core Web API, where are the templates to create new projects?
Keep up the work for the VB community. Do you know if the datasources window will be supported in .net 5 or 6? Or is this a much loved relic of .net 4.8?
<
p>Downloaded the new ver of c# and love the speed.
Kathleen, I still can’t find a way to actually make a label in front of an image that is transparent but still allow a click through event.
Thanks for any help. //ji John in Oregon
Hello Kathleen!
A question I have in relation to Visual Basic inside VS2022...
What kind of project is Visual Basic able to work on? Is it restricted to Windows Forms, Windows Services, or Console type applications only?
I develop in VB for a long time, but always desktop apps.
I am absolutely in love with Visual Basic.
For me it's the most beautiful programming language.
I want to work with web API, but everything I...
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...
Apparently you aren’t familiar with C#?
While I think an
out
parameter and an overload can pretty much replace anOptional ByRef
, I also think that is a very questionable construct in VB.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,...
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...
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......
Well said and I share your opinion 100%.
thanks
Why this post is not in the Language->Visual Basic blog?
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
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...
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...
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!
+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?
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.