Visual Basic Devs: Master Visual Studio
Visual Basic Devs: Master Visual Studio
The Visual Studio integrated development environment is a creative launching pad that you can use to edit, debug,
and build code, and then publish an app. An integrated development environment (IDE ) is a feature-rich program
that can be used for many aspects of software development. Over and above the standard editor and debugger
that most IDEs provide, Visual Studio includes compilers, code completion tools, graphical designers, and many
more features to ease the software development process.
This image shows Visual Studio with an open project and several key tool windows you'll likely use:
Solution Explorer (top right) lets you view, navigate, and manage your code files. Solution Explorer can
help organize your code by grouping the files into solutions and projects.
The editor window (center), where you'll likely spend a majority of your time, displays file contents. This is
where you can edit code or design a user interface such as a window with buttons and text boxes.
The Output window (bottom center) is where Visual Studio sends notifications such as debugging and error
messages, compiler warnings, publishing status messages, and more. Each message source has its own tab.
Team Explorer (bottom right) lets you track work items and share code with others using version control
technologies such as Git and Team Foundation Version Control (TFVC ).
Editions
Visual Studio is available for Windows and Mac. Visual Studio for Mac has many of the same features as Visual
Studio 2017, and is optimized for developing cross-platform and mobile apps. This article focuses on the Windows
version of Visual Studio 2017.
There are three editions of Visual Studio 2017: Community, Professional, and Enterprise. See Compare Visual
Studio 2017 IDEs to learn about which features are supported in each edition.
IntelliSense
IntelliSense is a term for a set of features that displays information about your code directly in the editor
and, in some cases, write small bits of code for you. It's like having basic documentation inline in the editor,
which saves you from having to look up type information elsewhere. IntelliSense features vary by language.
For more information, see C# IntelliSense, Visual C++ IntelliSense, JavaScript IntelliSense, and Visual Basic
IntelliSense. The following illustration shows how IntelliSense displays a member list for a type:
Search box
Visual Studio can seem overwhelming at times with so many menus, options, and properties. The search
box is a great way to rapidly find what you need in Visual Studio. When you start typing the name of
something you're looking for, Visual Studio lists results that take you exactly where you need to go. If you
need to add functionality to Visual Studio, for example to add support for an additional programming
language, the search box provides results that open Visual Studio Installer to install a workload or individual
component.
TIP
Press Ctrl+Q as a shortcut to the search box.
Live Share
Collaboratively edit and debug with others in real time, regardless of what your app type or programming
language. You can instantly and securely share your project and, as needed, debugging sessions, terminal
instances, localhost web apps, voice calls, and more.
Call Hierarchy
The Call Hierarchy window shows the methods that call a selected method. This can be useful information
when you're thinking about changing or removing the method, or when you're trying to track down a bug.
CodeLens
CodeLens helps you find references to your code, changes to your code, linked bugs, work items, code
reviews, and unit tests, all without leaving the editor.
Go To Definition
The Go To Definition feature takes you directly to the location where a function or type is defined.
Peek Definition
The Peek Definition window shows the definition of a method or type without actually opening a separate
file.
When you open Visual Studio for the first time, you can optionally sign in using your Microsoft account or your
work or school account.
Create a program
Let's dive in and create a simple program.
1. On the Visual Studio menu bar, choose File > New Project.
The New Project dialog box shows several project templates. A template contains the basic files and
settings needed for a given project type.
2. Choose the .NET Core category under Visual Basic, and then choose the Console App (.NET Core)
template. In the Name text box, type HelloWorld, and then select the OK button.
NOTE
If you don't see the .NET Core category, you need to install the .NET Core cross-platform development
workload. To do this, choose the Open Visual Studio Installer link on the bottom left of the New Project dialog.
After Visual Studio Installer opens, scroll down and select the .NET Core cross-platform development workload,
and then select Modify.
Visual Studio creates the project. It's a simple "Hello World" application that calls the Console.WriteLine()
method to display the literal string "Hello World!" in the console (program output) window.
Shortly, you should see something like the following:
The Visual Basic code for the app appears in the editor window, which takes up most of the space. Notice
that the text is automatically colorized to indicate different parts of the code, such as keywords and types. In
addition, small, vertical dashed lines in the code indicate which braces match one another, and line numbers
help you locate code later. You can choose the small, boxed minus signs to collapse or expand blocks of
code. This code outlining feature lets you hide code you don't need, helping to minimize onscreen clutter.
The project files are listed on the right side in a window called Solution Explorer.
There are other menus and tool windows available, but let's move on for now.
3. Now, start the app. You can do this by choosing Start Without Debugging from the Debug menu on the
menu bar. You can also press Ctrl+F5.
Visual Studio builds the app, and a console window opens with the message Hello World!. You now have a
running app!
4. To close the console window, press any key on your keyboard.
5. Let's add some additional code to the app. Add the following Visual Basic code before the line that says
Console.WriteLine("Hello World!") :
This code displays What is your name? in the console window, and then waits until the user enters some
text followed by the Enter key.
6. Change the line that says Console.WriteLine("Hello World!") to the following code:
9. Press any key to close the console window and stop the running program.
1. On the Visual Studio menu bar, choose File > New Project.
The Create a new project window opens and shows several project templates. A template contains the
basic files and settings needed for a given project type.
2. To find the template we want, type or enter .net core console in the search box. The list of available
templates is automatically filtered based on the keywords you entered. You can further filter the template
results by choosing Visual Basic from the Language drop-down list.
3. Select the Console App (.NET Core) template, and then choose Next.
4. In the Configure your new project window, enter HelloWorld in the Project name box, optionally
change the directory location for your project files, and then choose Create.
Visual Studio creates the project. It's a simple "Hello World" application that calls the Console.WriteLine()
method to display the literal string "Hello World!" in the console (program output) window.
Shortly, you should see something like the following:
The Visual Basic code for the app appears in the editor window, which takes up most of the space. Notice
that the text is automatically colorized to indicate different parts of the code, such as keywords and types. In
addition, small, vertical dashed lines in the code indicate which braces match one another, and line numbers
help you locate code later. You can choose the small, boxed minus signs to collapse or expand blocks of
code. This code outlining feature lets you hide code you don't need, helping to minimize onscreen clutter.
The project files are listed on the right side in a window called Solution Explorer.
There are other menus and tool windows available, but let's move on for now.
5. Now, start the app. You can do this by choosing Start Without Debugging from the Debug menu on the
menu bar. You can also press Ctrl+F5.
Visual Studio builds the app, and a console window opens with the message Hello World!. You now have a
running app!
6. To close the console window, press any key on your keyboard.
7. Let's add some additional code to the app. Add the following Visual Basic code before the line that says
Console.WriteLine("Hello World!") :
This code displays What is your name? in the console window, and then waits until the user enters some
text followed by the Enter key.
8. Change the line that says Console.WriteLine("Hello World!") to the following code:
11. Press any key to close the console window and stop the running program.
The variable is renamed across the project, which in our case is only two places.
4. Now let's take a look at IntelliSense. Below the line that says Console.WriteLine("Hello " + username + "!") ,
type the following code fragment:
A box displays the members of the DateTime class. In addition, the description of the currently selected
member displays in a separate box.
5. Select the member named Now, which is a property of the class, by double-clicking on it or selecting it
using the up or down arrow keys and then pressing Tab.
6. Below that, type in or paste the following lines of code:
TIP
Console.Write is a little different to Console.WriteLine in that it doesn't add a line terminator after it prints. That
means that the next piece of text that's sent to the output will print on the same line. You can hover over each of
these methods in your code to see their description.
7. Next, we'll use refactoring again to make the code a little more concise. Click on the variable now in the line
Dim now = Date.Now .
Notice that a little screwdriver icon appears in the margin on that line.
8. Click the screwdriver icon to see what suggestions Visual Studio has available. In this case, it's showing the
Inline temporary variable refactoring to remove a line of code without changing the overall behavior of the
code:
10. Run the program again by pressing Ctrl+F5. The output looks something like this:
Debug code
When you write code, you need to run it and test it for bugs. Visual Studio's debugging system lets you step
through code one statement at a time and inspect variables as you go. You can set breakpoints that stop execution
of the code at a particular line. You can observe how the value of a variable changes as the code runs, and more.
Let's set a breakpoint to see the value of the username variable while the program is "in flight".
1. Find the line of code that says Console.WriteLine("Hello " + username + "!") . To set a breakpoint on this line
of code, that is, to make the program pause execution at this line, click in the far left margin of the editor. You
can also click anywhere on the line of code and then press F9.
A red circle appears in the far left margin, and the code is highlighted in red.
2. Start debugging by selecting Debug > Start Debugging or by pressing F5.
3. When the console window appears and asks for your name, type it in and press Enter.
The focus returns to the Visual Studio code editor and the line of code with the breakpoint is highlighted in
yellow. This signifies that it's the next line of code that the program will execute.
4. Hover your mouse over the username variable to see its value. Alternatively, you can right-click on
username and select Add Watch to add the variable to the Watch window, where you can also see its
value.
Next steps
Explore Visual Studio further by following along with one of these introductory articles:
Learn to use the code editor
Learn about projects and solutions
See also
Discover more Visual Studio features
Visit visualstudio.microsoft.com
Read The Visual Studio blog
Learn to use the code editor
8/30/2019 • 6 minutes to read • Edit Online
In this 10-minute introduction to the code editor in Visual Studio, we'll add code to a file to look at some of the
ways that Visual Studio makes writing, navigating, and understanding code easier.
TIP
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
TIP
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
This article assumes you're already familiar with Visual Basic. If you aren't, we suggest you look at a tutorial such as
Get started with Visual Basic in Visual Studio first.
TIP
To follow along with this article, make sure you have the Visual Basic settings selected for Visual Studio. For information about
selecting settings for the integrated development environment (IDE), see Select environment settings.
There are snippets for determining if a file exists on the computer, writing to a text file, reading a registry value,
executing a SQL query, creating a For Each...Next statement, and many more.
2. We're not using the morewords array, but we may use it later so we don't want to completely delete it.
Instead, let's comment out those lines. Select the entire definition of morewords to the closing curly brace,
and then choose the Comment out the selected lines button on the toolbar. If you prefer to use the
keyboard, press Ctrl+K, Ctrl+C.
The Visual Basic comment character ' is added to the beginning of each selected line to comment out the
code.
The code block collapses to just the first line, followed by an ellipsis ( ... ). To expand the code block again, click the
same gray box that now has a plus sign in it, or press Ctrl+M, Ctrl+M again. This feature is called Outlining and is
especially useful when you're collapsing long methods or entire classes.
2. Close the peeked definition window by choosing the small box with an "x" at the top right of the pop-up
window.
You see IntelliSense show you Quick Info about the query symbol.
2. To insert the rest of the word query by using IntelliSense's word completion functionality, press Tab.
3. Finish off the code block to look like the following code.
Refactor a name
Nobody gets code right the first time, and one of the things you might have to change is the name of a variable or
method. Let's try out Visual Studio's refactor functionality to rename the _words variable to words .
1. Place your cursor over the definition of the _words variable and choose Rename from the right-click or
context menu.
A pop-up Rename dialog box appears at the top right of the editor.
2. With the variable _words still selected, type in the desired name of words. Notice that the reference to
words in the query is also automatically renamed. Before you press Enter or click Apply, select the Include
comments checkbox in the Rename pop-up box.
Next steps
Learn about projects and solutions
See also
Code snippets
Navigate code
Outlining
Go To Definition and Peek Definition
Refactoring
Use IntelliSense
Learn about projects and solutions using Visual Basic
8/30/2019 • 8 minutes to read • Edit Online
In this introductory article, we'll explore what it means to create a solution and a project in Visual Studio. A
solution is a container that's used to organize one or more related code projects, for example a class library project
and a corresponding test project. We'll look at the properties of a project and some of the files it can contain. We'll
also create a reference from one project to another.
TIP
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
TIP
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
We'll construct a solution and project from scratch as an educational exercise to understand the concept of a
project. In your general use of Visual Studio, you'll likely use some of the various project templates that Visual
Studio offers when you create a new project.
NOTE
Solutions and projects aren't required to develop apps in Visual Studio. You can also just open a folder that contains code
and start coding, building, and debugging. For example, if you clone a GitHub repo, it might not contain Visual Studio
projects and solutions. For more information, see Develop code in Visual Studio without projects or solutions.
NOTE
If you don't see Visual Basic in the left pane of the dialog box, you need to install the .NET desktop development
Visual Studio workload. Visual Studio uses workload-based installation to only install the components you need for
the type of development you do. An easy way to install a new workload is to choose the Open Visual Studio
Installer link in the bottom left corner of the Add New Project dialog box. After Visual Studio Installer launches,
choose the .NET desktop development workload and then the Modify button.
1. From the right-click or context menu of Solution 'QuickSolution' in Solution Explorer, choose Add >
New Project.
A dialog box opens that says Add a new project.
2. Enter the text empty into the search box at the top, and then select Visual Basic under Language.
3. Select the Empty Project (.NET Framework) template, and then choose Next.
4. Name the project QuickDate, then choose Create.
A project named QuickDate appears beneath the solution in Solution Explorer. Currently it contains a
single file called App.config.
NOTE
If you don't see the Empty Project (.NET Framework) template, you need to install the .NET desktop
development Visual Studio workload. Visual Studio uses workload-based installation to only install the components
you need for the type of development you do. An easy way to install a new workload when you're creating a new
project is to choose the Install more tools and features link under the text that says Not finding what you're
looking for?. After Visual Studio Installer launches, choose the .NET desktop development workload and then the
Modify button.
Class Calendar
Public Shared Function GetCurrentDate() As Date
Return DateTime.Now.Date
End Function
End Class
The Calendar class contains a single function, GetCurrentDate , that returns the current date.
4. Open the project properties by double-clicking My Project in Solution Explorer. On the Application
tab, change Application type to Class Library. This step is necessary to build the project successfully.
5. Build the project by right-clicking on QuickDate in Solution Explorer and choosing Build. You should
see a successful build message in the Output window.
2. In the Add a new project dialog box, enter the text unit test into the search box at the top, and then select
Visual Basic under Language.
3. Choose the Unit Test Project (.NET Framework) project template, and then choose Next.
4. Name the project QuickTest, and then choose Create.
A second project is added to Solution Explorer, and a file named UnitTest1.vb opens in the editor.
End Class
You'll see a red squiggle under some of the code. We'll fix this error by making the test project a friend
assembly to the QuickDate project.
2. Back in the QuickDate project, open the Calendar.vb file if it's not already open, and add the following
Imports statement and InternalsVisibleToAttribute attribute, to resolve the error in the test project.
Imports System.Runtime.CompilerServices
<Assembly: InternalsVisibleTo("QuickTest")>
2. Explore some of the other tabs of the project's property pages, such as Compile and Settings. These tabs
are different for different types of projects.
Next steps
If you want to further explore Visual Studio, consider creating an app by following one of the Visual Basic
tutorials.
See also
Create projects and solutions
Manage project and solution properties
Manage references in a project
Develop code in Visual Studio without projects or solutions
Visual Studio IDE overview
Features of Visual Studio
8/30/2019 • 7 minutes to read • Edit Online
The Visual Studio IDE overview article gives a basic introduction to Visual Studio. This article describes features
that might be more appropriate for experienced developers, or those developers who are already familiar with
Visual Studio.
Modular installation
Visual Studio's modular installer enables you to choose and install workloads. Workloads are groups of features
needed for the programming language or platform you prefer. This strategy helps to keep the footprint of the
Visual Studio installation smaller, which means it installs and updates faster too.
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
To learn more about setting up Visual Studio on your system, see Install Visual Studio.
After you install the Azure development workload, the following Cloud templates for C# are available in the
New Project dialog:
Visual Studio's Cloud Explorer lets you view and manage your Azure-based cloud resources within Visual Studio.
These resources may include virtual machines, tables, SQL databases, and more. Cloud Explorer shows the Azure
resources in all the accounts managed under the Azure subscription you're logged into. And if a particular
operation requires the Azure portal, Cloud Explorer provides links that take you to the place in the portal where
you need to go.
You can leverage Azure services for your apps using Connected Services such as:
Active Directory connected service so users can use their accounts from Azure Active Directory to connect to
web apps
Azure Storage connected service for blob storage, queues, and tables
Key Vault connected service to manage secrets for web apps
The available Connected Services depend on your project type. Add a service by right-clicking on the project in
Solution Explorer and choosing Add > Connected Service.
For more information, see Move to the cloud With Visual Studio and Azure.
You can also automate your build process to build the code that the devs on your team have checked into version
control. For example, you can build one or more projects nightly or every time that code is checked in. For more
information, see Azure Pipelines.
See also
Visual Studio IDE overview
What's new in Visual Studio 2017
What's new in Visual Studio 2019
Tutorial: Get started with Visual Basic in Visual Studio
9/11/2019 • 6 minutes to read • Edit Online
In this tutorial for Visual Basic (VB ), you'll use Visual Studio to create and run a few different console apps and
explore some features of the Visual Studio integrated development environment (IDE ) while you do so.
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
Create a project
First, we'll create a Visual Basic application project. The project type comes with all the template files you'll need,
before you've even added anything!
1. Open Visual Studio 2017.
2. From the top menu bar, choose File > New > Project.
3. In the New Project dialog box in the left pane, expand Visual Basic, and then choose .NET Core. In the
middle pane, choose Console App (.NET Core). Then name the project WhatIsYourName.
NOTE
Some of the screenshots in this tutorial use the dark theme. If you aren't using the dark theme but would like to, see the
Personalize the Visual Studio IDE and Editor page to learn how.
Then, in the Visual Studio Installer, choose the .NET Core cross-platform development workload.
After that, choose the Modify button in the Visual Studio Installer. You might be prompted to save your work; if so,
do so. Next, choose Continue to install the workload. Then, return to step 2 in this "Create a project" procedure.
4. In the Configure your new project window, type or enter WhatIsYourName in the Project name box.
Then, choose Create.
This code replaces the existing WriteLine, Write, and ReadKey statements.
3. When the console window opens, enter your name. Your console window should look similar to the
following screenshot:
This code replaces the existing WriteLine, Write, and ReadKey statements.
2. When the console window opens, enter your name. Your console window should look similar to the
following screenshot:
5. Click CalculateThis to run your program. Your console window should look similar to the following
screenshot:
Next steps
Congratulations on completing this tutorial! To learn even more, see the following tutorial.
Build a library with Visual Basic and the .NET Core SDK in Visual Studio
See also
Visual Basic language walkthroughs
Visual Basic language reference
IntelliSense for Visual Basic code files
Tutorial: Create a simple application with Visual Basic
9/10/2019 • 9 minutes to read • Edit Online
By completing this tutorial, you'll become familiar with many of the tools, dialog boxes, and designers that you can
use when you develop applications with Visual Studio. You'll create a "Hello, World" application, design the UI, add
code, and debug errors, while you learn about working in the integrated development environment (IDE ).
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
After Visual Studio launches, you'll see tool windows, the menus and toolbars, and the main window space. Tool
windows are docked on the left and right sides of the application window, with Quick Launch, the menu bar, and
the standard toolbar at the top. In the center of the application window is the Start Page. When you load a solution
or project, editors and designers appear in the space where the Start Page is. When you develop an application,
you'll spend most of your time in this central area.
When you launch Visual Studio, the start window opens first. Select Continue without code to open the
development environment. You'll see tool windows, the menus and toolbars, and the main window space. Tool
windows are docked on the left and right sides of the application window, with a search box, the menu bar, and the
standard toolbar at the top. When you load a solution or project, editors and designers appear in the central space
of the application window. When you develop an application, you'll spend most of your time in this central area.
2. In the New Project dialog, select the Installed > Visual Basic > Windows Desktop category, and then
select the WPF App (.NET Framework) template. Name the project HelloWPFApp, and select OK.
Visual Studio creates the HelloWPFApp project and solution, and Solution Explorer shows the various files. The
WPF Designer shows a design view and a XAML view of MainWindow.xaml in a split view. You can slide the
splitter to show more or less of either view. You can choose to see only the visual view or only the XAML view. The
following items appear in Solution Explorer:
NOTE
For more information about XAML (eXtensible Application Markup Language), see the XAML overview for WPF page.
After you create the project, you can customize it. By using the Properties window (found on the View menu), you
can display and change options for project items, controls, and other items in an application.
Change the name of MainWindow.xaml
Let's give MainWindow a more specific name. In Solution Explorer, right-click on MainWindow.xaml and choose
Rename. Rename the file to Greetings.xaml.
3. Add a TextBlock control to the design surface by choosing the TextBlock item and dragging it to the
window on the design surface. Center the control near the top of the window. In Visual Studio 2019 and
later, you can use the red guidelines to center the control.
Your window should resemble the following illustration:
The XAML markup should look something like the following example:
2. Center the TextBlock again if necessary, and save your changes by pressing Ctrl+S or using the File menu
item.
Next, you'll add two RadioButton controls to the form.
Add radio buttons
1. In the Toolbox, find the RadioButton control.
2. Add two RadioButton controls to the design surface by choosing the RadioButton item and dragging it to
the window on the design surface. Move the buttons (by selecting them and using the arrow keys) so that
the buttons appear side by side under the TextBlock control. Use the red guidelines to align the controls.
Your window should look like this:
3. In the Properties window for the left RadioButton control, change the Name property (the property at the
top of the Properties window ) to HelloButton .
4. In the Properties window for the right RadioButton control, change the Name property to GoodbyeButton ,
and then save your changes.
You can now add display text for each RadioButton control. The following procedure updates the Content
property for a RadioButton control.
Add display text for each radio button
Update the Content attribute for the HelloButton and GoodbyeButton to "Hello" and "Goodbye" in the XAML.
The XAML markup should now look similar to the following example:
<Grid>
<TextBlock HorizontalAlignment="Left" Margin="252,47,0,0" TextWrapping="Wrap" Text="Select a message
option and then choose the Display button." VerticalAlignment="Top"/>
<RadioButton x:Name="HelloButton" Content="Hello" HorizontalAlignment="Left" Margin="297,161,0,0"
VerticalAlignment="Top"/>
<RadioButton x:Name="GoodbyeButton" Content="Goodbye" HorizontalAlignment="Left" Margin="488,161,0,0"
VerticalAlignment="Top"/>
</Grid>
IsChecked="True"
End Sub
Start the debugger again (press F5). You should see the Greetings window of the application.
Now close the application window to stop debugging.
Debug with breakpoints
You can test the code during debugging by adding some breakpoints. You can add breakpoints by choosing Debug
> Toggle Breakpoint, by clicking in the left margin of the editor next to the line of code where you want the break
to occur, or by pressing F9.
Add breakpoints
1. Open Greetings.xaml.vb, and select the following line: MessageBox.Show("Hello.")
2. Add a breakpoint by pressing F9 or from the menu by selecting Debug, then Toggle Breakpoint.
A red circle appears next to the line of code in the far left margin of the editor window.
3. Select the following line: MessageBox.Show("Goodbye.") .
4. Press the F9 key to add a breakpoint, and then press F5 to start debugging.
5. In the Greetings window, choose the Hello radio button, and then choose the Display button.
The line MessageBox.Show("Hello.") is highlighted in yellow. At the bottom of the IDE, the Autos, Locals, and
Watch windows are docked together on the left side, and the Call Stack, Breakpoints, Exception Settings,
Command, Immediate, and Output windows are docked together on the right side.
6. On the menu bar, choose Debug > Step Out.
The application resumes execution, and a message box with the word "Hello" appears.
7. Choose the OK button on the message box to close it.
8. In the Greetings window, choose the Goodbye radio button, and then choose the Display button.
The line MessageBox.Show("Goodbye.") is highlighted in yellow.
9. Choose the F5 key to continue debugging. When the message box appears, choose the OK button on the
message box to close it.
10. Close the application window to stop debugging.
11. On the menu bar, choose Debug > Disable All Breakpoints.
View a representation of the UI elements
In the running app, you should see a widget that appears at the top of your window. This is a runtime helper that
provides quick access to some helpful debugging features. Click on the first button, Go to Live Visual Tree. You
should see a window with a tree that contains all the visual elements of your page. Expand the nodes to find the
buttons you added.
Build a release version of the application
Now that you've verified that everything works, you can prepare a release build of the application.
1. On the main menu, select Build > Clean solution to delete intermediate files and output files that were
created during previous builds. This is not necessary, but it cleans up the debug build outputs.
2. Change the build configuration for HelloWPFApp from Debug to Release by using the dropdown control
on the toolbar (it says "Debug" currently).
3. Build the solution by choosing Build > Build Solution.
Congratulations on completing this tutorial! You can find the .exe you built under your solution and project
directory (...\HelloWPFApp\HelloWPFApp\bin\Release).
See also
What's new in Visual Studio 2017
Productivity tips
What's new in Visual Studio 2019
Productivity tips
Create a Windows Forms app in Visual Studio with
Visual Basic
9/30/2019 • 4 minutes to read • Edit Online
In this short introduction to the Visual Studio integrated development environment (IDE ), you'll create a simple
Visual Basic application that has a Windows-based user interface (UI).
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
NOTE
Some of the screenshots in this tutorial use the dark theme. If you aren't using the dark theme but would like to, see the
Personalize the Visual Studio IDE and Editor page to learn how.
Create a project
First, you'll create a Visual Basic application project. The project type comes with all the template files you'll need,
before you've even added anything.
1. Open Visual Studio 2017.
2. From the top menu bar, choose File > New > Project.
3. In the New Project dialog box in the left pane, expand Visual Basic, and then choose Windows Desktop.
In the middle pane, choose Windows Forms App (.NET Framework). Then name the file HelloWorld .
If you don't see the Windows Forms App (.NET Framework) project template, cancel out of the New
Project dialog box and from the top menu bar, choose Tools > Get Tools and Features. The Visual Studio
Installer launches. Choose the .NET desktop development workload, then choose Modify.
Next, in the Visual Studio Installer, choose the Choose the .NET desktop development workload.
After that, choose the Modify button in the Visual Studio Installer. You might be prompted to save your work; if so,
do so. Next, choose Continue to install the workload. Then, return to step 2 in this "Create a project" procedure.
4. In the Configure your new project window, type or enter HelloWorld in the Project name box. Then,
choose Create.
3. Click the Button control and then drag it onto the form.
4. In the Appearance section (or the Fonts section) of the Properties window, type Click this , and then
press Enter.
(If you don't see the Properties window, you can open it from the menu bar. To do so, click View >
Properties Window. Or, press F4.)
5. In the Design section of the Properties window, change the name from Button1 to btnClickThis , and
then press Enter.
NOTE
If you've alphabetized the list in the Properties window, Button1 appears in the (DataBindings) section, instead.
Several things will happen. In the Visual Studio IDE, the Diagnostics Tools window will open, and an
Output window will open, too. But outside of the IDE, a Form1 dialog box appears. It will include your
Click this button and text that says Label1.
2. Click the Click this button in the Form1 dialog box. Notice that the Label1 text changes to Hello World!.
Next steps
To learn more, continue with the following tutorial:
Tutorial: Create a picture viewer
See also
More Visual Basic tutorials
C# tutorials
C++ tutorials
Tutorial: Open a project from a repo
8/30/2019 • 3 minutes to read • Edit Online
In this tutorial, you'll use Visual Studio to connect to a repository for the first time and then open a project from it.
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
4. In the box that says Enter the URL of a Git repo to clone, type or paste the URL for your repo, and then
press Enter. (You might receive a prompt to sign in to GitHub; if so, do so.)
After Visual Studio clones your repo, Team Explorer closes and Solution Explorer opens. A message appears
that says Click on Solutions and Folders above to view a list of Solutions. Choose Solutions and Folders.
5. If you have a solution file available, it will appear in the "Solutions and Folders" fly-out menu. Choose it, and
Visual Studio opens your solution.
If you do not have a solution file (specifically, a .sln file) in your repo, the fly-out menu will say "No Solutions
Found." However, you can double-click any file from the folder menu to open it in the Visual Studio code
editor.
Review your work
View the following animation to check the work that you completed in the previous section.
1. Open Visual Studio 2019.
2. On the start window, choose Clone or check out code.
If you do not have a solution file (specifically, a .sln file) in your repo, the fly-out menu will say "No Solutions
Found." However, you can double-click any file from the folder menu to open it in the Visual Studio code
editor.
Open a project from an Azure DevOps repo
1. Open Visual Studio 2017.
2. From the top menu bar, choose File > Open > Open from Source Control.
The Team Explorer - Connect pane opens.
NOTE
What you see in the list box depends on the Azure DevOps repositories that you have access to.
5. After Visual Studio clones your repo, Team Explorer closes and Solution Explorer opens. A message appears
that says Click on Solutions and Folders above to view a list of Solutions. Choose Solutions and Folders.
A solution file (specifically, a .sln file), will appear in the "Solutions and Folders" fly-out menu. Choose it, and
Visual Studio opens your solution.
If you do not have a solution file in your repo, the fly-out menu will say "No Solutions Found". However, you
can double-click any file from the folder menu to open it in the Visual Studio code editor.
1. Open Visual Studio 2019.
2. On the start window, choose Clone or check out code.
Visual Studio opens Team Explorer and a notification appears when the clone is complete.
5. To view your folders and files, choose the Show Folder View link.
If you do not have a solution file in your repo, a "No Solutions Found" message appears. However, you can
double-click any file from the folder menu to open it in the Visual Studio code editor.
Next steps
If you're ready to code with Visual Studio, dive into any of the following language-specific tutorials:
Visual Studio tutorials | C#
Visual Studio tutorials | Visual Basic
Visual Studio tutorials | C++
Visual Studio tutorials | Python
Visual Studio tutorials | JavaScript, TypeScript, and Node.js
See also
Azure DevOps Services: Get started with Azure Repos and Visual Studio
Microsoft Learn: Get started with Azure DevOps
Learn to use the code editor
8/30/2019 • 6 minutes to read • Edit Online
In this 10-minute introduction to the code editor in Visual Studio, we'll add code to a file to look at some of the
ways that Visual Studio makes writing, navigating, and understanding code easier.
TIP
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
TIP
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
This article assumes you're already familiar with Visual Basic. If you aren't, we suggest you look at a tutorial such
as Get started with Visual Basic in Visual Studio first.
TIP
To follow along with this article, make sure you have the Visual Basic settings selected for Visual Studio. For information
about selecting settings for the integrated development environment (IDE), see Select environment settings.
There are snippets for determining if a file exists on the computer, writing to a text file, reading a registry value,
executing a SQL query, creating a For Each...Next statement, and many more.
2. We're not using the morewords array, but we may use it later so we don't want to completely delete it.
Instead, let's comment out those lines. Select the entire definition of morewords to the closing curly brace,
and then choose the Comment out the selected lines button on the toolbar. If you prefer to use the
keyboard, press Ctrl+K, Ctrl+C.
The Visual Basic comment character ' is added to the beginning of each selected line to comment out the
code.
The code block collapses to just the first line, followed by an ellipsis ( ... ). To expand the code block again, click
the same gray box that now has a plus sign in it, or press Ctrl+M, Ctrl+M again. This feature is called Outlining
and is especially useful when you're collapsing long methods or entire classes.
2. Close the peeked definition window by choosing the small box with an "x" at the top right of the pop-up
window.
You see IntelliSense show you Quick Info about the query symbol.
2. To insert the rest of the word query by using IntelliSense's word completion functionality, press Tab.
3. Finish off the code block to look like the following code.
Refactor a name
Nobody gets code right the first time, and one of the things you might have to change is the name of a variable or
method. Let's try out Visual Studio's refactor functionality to rename the _words variable to words .
1. Place your cursor over the definition of the _words variable and choose Rename from the right-click or
context menu.
A pop-up Rename dialog box appears at the top right of the editor.
2. With the variable _words still selected, type in the desired name of words. Notice that the reference to
words in the query is also automatically renamed. Before you press Enter or click Apply, select the
Include comments checkbox in the Rename pop-up box.
Next steps
Learn about projects and solutions
See also
Code snippets
Navigate code
Outlining
Go To Definition and Peek Definition
Refactoring
Use IntelliSense
Compile and build in Visual Studio
9/23/2019 • 2 minutes to read • Edit Online
When you build source code, the build engine creates assemblies and executable applications. In general, the build
process is very similar across many different project types such as Windows, ASP.NET, mobile apps, and others.
The build process is also similar across programming languages such as C#, Visual Basic, C++, and F#.
By building your code often, you can quickly identify compile-time errors, such as incorrect syntax, misspelled
keywords, and type mismatches. You can also detect and correct run-time errors, such as logic errors and semantic
errors, by building and running debug versions of the code.
A successful build validates that the application's source code contains correct syntax and that all static references
to libraries, assemblies, and other components can resolve. An application executable is produced that can be
tested for proper functioning in both a debugging environment and through a variety of manual and automated
tests to validate code quality. Once the application has been fully tested, you can compile a release version to
deploy to your customers. For an introduction to this process, see Walkthrough: Building an application.
You can use any of the following methods to build an application: the Visual Studio IDE, the MSBuild command-
line tools, and Azure Pipelines:
The documentation in this section goes into further details of the IDE -based build process. For more information
on the other methods, see MSBuild and Azure Pipelines, respectively.
NOTE
This topic applies to Visual Studio on Windows. For Visual Studio for Mac, see Compile and build in Visual Studio for Mac.
See also
Building (compiling) website projects
Compile and build (Visual Studio for Mac)
Tutorial: Learn to debug Visual Basic code using
Visual Studio
8/30/2019 • 11 minutes to read • Edit Online
This article introduces the features of the Visual Studio debugger in a step-by-step walkthrough. If you want a
higher-level view of the debugger features, see First look at the debugger. When you debug your app, it usually
means that you are running your application with the debugger attached. When you do this, the debugger provides
many ways to see what your code is doing while it runs. You can step through your code and look at the values
stored in variables, you can set watches on variables to see when values change, you can examine the execution
path of your code, see whether a branch of code is running, and so on. If this is the first time that you've tried to
debug code, you may want to read Debugging for absolute beginners before going through this article.
In this tutorial, you will:
Start the debugger and hit breakpoints.
Learn commands to step through code in the debugger
Inspect variables in data tips and debugger windows
Examine the call stack
Prerequisites
You must have Visual Studio 2019 installed and the .NET desktop development workload.
You must have Visual Studio 2017 installed and the .NET desktop development workload.
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
If you haven't already installed Visual Studio, go to the Visual Studio downloads page to install it for free.
If you need to install the workload but already have Visual Studio, go to Tools > Get Tools and Features..., which
opens the Visual Studio Installer. The Visual Studio Installer launches. Choose the .NET desktop development
workload, then choose Modify.
Create a project
1. Open Visual Studio.
Press Esc to close the start window. Type Ctrl + Q to open the search box, type visual basic, choose
Templates, then choose Create new Console App (.NET Framework) project. In the dialog box that
appears, type a name like get-started-debugging, and then choose Create.
From the top menu bar, choose File > New > Project. In the left pane of the New project dialog box,
under Visual Basic, choose Windows Desktop, and then in the middle pane choose Console App (.NET
Framework). Then, type a name like get-started-debugging and click OK.
If you don't see the Console App (.NET Framework) project template, go to Tools > Get Tools and
Features..., which opens the Visual Studio Installer. Choose the .NET desktop development workload,
then choose Modify.
Visual Studio creates the project.
2. In Module1.vb, replace the following code
Module Module1
Sub Main()
End Sub
End Module
Imports System
Imports System.Collections.Generic
Module Module1
End Sub
End Module
' Output:
' Drawing a rectangle
' Performing base class drawing tasks
' Drawing a triangle
' Performing base class drawing tasks
' Drawing a circle
' Performing base class drawing tasks
Drawing a rectangle
Performing base class drawing tasks
Drawing a triangle
Performing base class drawing tasks
Drawing a circle
Performing base class drawing tasks
In this tutorial, we'll take a closer look at this app using the debugger and get a look at the debugger
features.
2. Stop the debugger by pressing the red stop button.
Breakpoints are the most basic and essential feature of reliable debugging. A breakpoint indicates where
Visual Studio should suspend your running code so you can take a look at the values of variables, or the
behavior of memory, or whether or not a branch of code is getting run.
2. Press F5 or the Start Debugging button , the app starts, and the debugger runs to the line of code where
you set the breakpoint.
The yellow arrow represents the statement on which the debugger paused, which also suspends app
execution at the same point (this statement has not yet executed).
If the app is not yet running, F5 starts the debugger and stops at the first breakpoint. Otherwise, F5
continues running the app to the next breakpoint.
Breakpoints are a useful feature when you know the line of code or the section of code that you want to
examine in detail.
F11 is the Step Into command and advances the app execution one statement at a time. F11 is a good way
to examine the execution flow in the most detail. (To move faster through code, we show you some other
options also.) By default, the debugger skips over non-user code (if you want more details, see Just My
Code).
2. Press F10 (or choose Debug > Step Over) a few times until the debugger stops on the MyBase.Draw
method call, and then press F10 one more time.
Notice this time that the debugger does not step into the Draw method of the base class ( Shape ). F10
advances the debugger without stepping into functions or methods in your app code (the code still
executes). By pressing F10 on the MyBase.Draw method call (instead of F11), we skipped over the
implementation code for MyBase.Draw (which maybe we're not interested in right now ).
NOTE
Depending on what type of code you edit in the debugger, you may see a warning message. In some scenarios, the
code will need to recompile before you can continue.
Step out
Let's say that you are done examining the Draw method in the Triangle class, and you want to get out of the
function but stay in the debugger. You can do this using the Step Out command.
1. Press Shift + F11 (or Debug > Step Out).
This command resumes app execution (and advances the debugger) until the current function returns.
You should be back in the For Each loop in the Main method.
Restart your app quickly
Click the Restart button in the Debug Toolbar (Ctrl + Shift + F5).
When you press Restart, it saves time versus stopping the app and restarting the debugger. The debugger pauses
at the first breakpoint that is hit by executing code.
The debugger stops again at the breakpoint you set, on the shape.Draw() method.
You can further expand objects to view their properties, such as the Height property of the rectangle.
Often, when debugging, you want a quick way to check property values on objects, and the data tips are a
good way to do it.
In the Autos window, you see variables and their current value. The Autos window shows all variables used
on the current line or the preceding line (Check documentation for language-specific behavior).
2. Next, look at the Locals window, in a tab next to the Autos window.
The Locals window shows you the variables that are in the current scope, that is, the current execution
context.
Set a watch
1. In the main code editor window, right-click the shapes object and choose Add Watch.
The Watch window opens at the bottom of the code editor. You can use a Watch window to specify a
variable (or an expression) that you want to keep an eye on.
Now, you have a watch set on the shapes object, and you can see its value change as you move through the
debugger. Unlike the other variable windows, the Watch window always shows the variables that you are
watching (they're grayed out when out of scope).
The Call Stack window shows the order in which methods and functions are getting called. The top line
shows the current function (the Rectangle.Draw method in this app). The second line shows that
Rectangle.Draw was called from the Main function, and so on.
NOTE
The Call Stack window is similar to the Debug perspective in some IDEs like Eclipse.
The call stack is a good way to examine and understand the execution flow of an app.
You can double-click a line of code to go look at that source code and that also changes the current scope
being inspected by the debugger. This action does not advance the debugger.
You can also use right-click menus from the Call Stack window to do other things. For example, you can
insert breakpoints into specified functions, advance the debugger using Run to Cursor, and go examine
source code. For more information, see How to: Examine the Call Stack.
2. Press F11.
The debugger reruns the Console.WriteLine method (you see duplicate output in the console window
output).
By changing the execution flow, you can do things like test different code execution paths or rerun code
without restarting the debugger.
WARNING
Often you need to be careful with this feature, and you see a warning in the tooltip. You may see other warnings, too.
Moving the pointer cannot revert your application to an earlier app state.
Next steps
In this tutorial, you've learned how to start the debugger, step through code, and inspect variables. You may want to
get a high-level look at debugger features along with links to more information.
First look at the debugger
Get started with unit testing
8/8/2019 • 4 minutes to read • Edit Online
Use Visual Studio to define and run unit tests to maintain code health, ensure code coverage, and find errors and
faults before your customers do. Run your unit tests frequently to make sure your code is working properly.
2. In Solution Explorer, select the solution node. Then, from the top menu bar, select File > Add > New
Project.
3. In the new project dialog box, find a unit test project template for the test framework you want to use and
select it.
Click Next, choose a name for the test project, and then click Create.
Choose a name for the test project, and then click OK.
The project is added to your solution.
4. In the unit test project, add a reference to the project you want to test by right-clicking on References or
Dependencies and then choosing Add Reference.
5. Select the project that contains the code you'll test and click OK.
After the tests have completed, a green check mark indicates that a test passed. A red "x" icon indicates that
a test failed.
TIP
You can use Test Explorer to run unit tests from the built-in test framework (MSTest) or from third-party test frameworks.
You can group tests into categories, filter the test list, and create, save, and run playlists of tests. You can also debug tests
and analyze test performance and code coverage.
NOTE
Live unit testing is available in Enterprise edition only.
1. Turn live unit testing from the Test menu by choosing Test > Live Unit Testing > Start.
2. View the results of the tests within the code editor window as you write and edit code.
3. Click a test result indicator to see more information, such as the names of the tests that cover that method.
For more information about live unit testing, see Live unit testing.
4. Add a reference from the test project to the project that contains the code you want to test.
Right-click on the project in Solution Explorer, and then select Add > Reference. (You can also add a
reference from the right-click menu of the References or Dependencies node.)
5. Add code to your test method.
6. Run the test from Test Explorer or by right-clicking on the test code and choosing Run Test(s).
See also
Walkthrough: Create and run unit tests for managed code
Create Unit Tests command
Generate tests with IntelliTest
Run tests with Test Explorer
Analyze code coverage
Create a database and add tables in Visual Studio
9/25/2019 • 5 minutes to read • Edit Online
You can use Visual Studio to create and update a local database file in SQL Server Express LocalDB. You can also
create a database by executing Transact-SQL statements in the SQL Server Object Explorer tool window in
Visual Studio. In this topic, we'll create an .mdf file and add tables and keys by using the Table Designer.
Prerequisites
To complete this walkthrough, you'll need the .NET desktop development and Data storage and processing
workloads installed in Visual Studio. To install them, open Visual Studio Installer and choose Modify (or More >
Modify) next to the version of Visual Studio you want to modify.
TIP
If you can't expand the Data Connections node, or the SampleDatabase.mdf connection is not listed, select the
Connect to Database button in the Server Explorer toolbar. In the Add Connection dialog box, make sure that
Microsoft SQL Server Database File is selected under Data source, and then browse to and select the
SampleDatabase.mdf file. Finish adding the connection by selecting OK.
4. Right-click on the CustomerID row, and then select Set Primary Key.
5. Right-click on the default row ( Id ), and then select Delete.
6. Name the Customers table by updating the first line in the script pane to match the following sample:
2. Set OrderID as the primary key, and then delete the default row.
3. Name the Orders table by updating the first line in the script pane to match the following sample:
2. In the text box that appears, replace the text ToTable with Customers.
3. In the T-SQL pane, update the last line to match the following sample:
IMPORTANT
Make sure that all order IDs and order quantities are integers and that each customer ID matches a value that you
specified in the CustomerID column of the Customers table.
See also
Accessing data in Visual Studio