Visual Studio Code 2019



-->

By Rick Anderson

This is the first tutorial of a series that teaches the basics of building an ASP.NET Core Razor Pages web app.

Visual Studio Code 2019

For a more advanced introduction aimed at developers who are familiar with controllers and views, see Introduction to Razor Pages.

  • x Code Action x EmmyLua Annotation x Multi Workspace x Semantic Tokens Type Format; Preview Goto Definition. Find All References. Auto Completion. Emmy Annotation. Version x Lua 5.1 x Lua 5.2 x Lua 5.3 x Lua 5.4 x LuaJIT; If you find any mistakes, please tell me or use Pull.
  • Learn how to use Visual Studio to develop applications, services. Visual Studio 2019 Release Notes. Improve your Visual Studio skills. Share your apps and code by using Web Deploy, InstallShield, NuGet, Continuous Integration, and more.

Visual Studio Code; Visual Studio for Mac; Visual Studio 2019 16.4 or later with the ASP.NET and web development workload.NET Core 3.1 SDK or later. Visual Studio Code; C# for Visual Studio Code (latest version).NET Core 3.1 SDK or later; The Visual Studio Code instructions use the.NET Core CLI for ASP.NET Core development functions such as. Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows. Download Visual Studio Code to experience a redefined code editor, optimized for building and debugging modern web and cloud applications.

At the end of the series, you'll have an app that manages a database of movies.

View or download sample code (how to download).

In this tutorial, you:

  • Create a Razor Pages web app.
  • Run the app.
  • Examine the project files.

At the end of this tutorial, you'll have a working Razor Pages web app that you'll enhance in later tutorials.

2019

Prerequisites

  • Visual Studio 2019 16.8 or later with the ASP.NET and web development workload

The Visual Studio Code instructions use the .NET CLI for ASP.NET Core development functions such as project creation. You can follow these instructions on macOS, Linux, or Windows and with any code editor. Minor changes may be required if you use something other than Visual Studio Code.

Create a Razor Pages web app

  1. Start Visual Studio and select Create a new project. For more information, see Create a new project in Visual Studio.

  2. In the Create a new project dialog, select ASP.NET Core Web Application, and then select Next.

  3. In the Configure your new project dialog, enter RazorPagesMovie for Project name. It's important to name the project RazorPagesMovie, including matching the capitalization, so the namespaces will match when you copy and paste example code.

  4. Select Create.

  5. In the Create a new ASP.NET Core web application dialog, select:

    1. .NET Core and ASP.NET Core 5.0 in the dropdowns.
    2. Web Application.
    3. Create.

    The following starter project is created:

  1. Open the integrated terminal.

  2. Change to the directory (cd) which will contain the project.

  3. Run the following commands:

    • The dotnet new command creates a new Razor Pages project in the RazorPagesMovie folder.
    • The code command opens the RazorPagesMovie folder in the current instance of Visual Studio Code.
  1. Select File > New Solution.

  2. In Visual Studio for Mac earlier than version 8.6, select .NET Core > App > Web Application > Next. In version 8.6 or later, select Web and Console > App > Web Application > Next.

  3. In the Configure the new Web Application dialog:

    1. Confirm that Authentication is set to No Authentication.
    2. If presented an option to select a Target Framework, select the latest .NET 5.x version.
    3. Select Next.
  4. Name the project RazorPagesMovie and select Create.

Run the app

  • Press Ctrl+F5 to run without the debugger.

    Visual Studio displays the following dialog:

    Select Yes if you trust the IIS Express SSL certificate.

    The following dialog is displayed:

    Select Yes if you agree to trust the development certificate.

    For information on trusting the Firefox browser, see Firefox SEC_ERROR_INADEQUATE_KEY_USAGE certificate error.

    Visual Studio starts IIS Express and runs the app. The address bar shows localhost:port# and not something like example.com. That's because localhost is the standard hostname for the local computer. Localhost only serves web requests from the local computer. When Visual Studio creates a web project, a random port is used for the web server.

  • Trust the HTTPS development certificate by running the following command:

    The preceding command doesn't work on Linux. See your Linux distribution's documentation for trusting a certificate.

    The preceding command displays the following dialog:

  • Select Yes if you agree to trust the development certificate.

    See Trust the ASP.NET Core HTTPS development certificate for more information.

For information on trusting the Firefox browser, see Firefox SEC_ERROR_INADEQUATE_KEY_USAGE certificate error.

  • Press Ctrl-F5 to run without the debugger.

    Visual Studio Code starts Kestrel, launches a browser, and navigates to http://localhost:5001. The address bar shows localhost:port# and not something like example.com. That's because localhost is the standard hostname for local computer. Localhost only serves web requests from the local computer.

Download

Visual Studio for Mac displays the following popup:

Select Yes if you trust the development certificate.

The following dialog is displayed:

Enter your password and select OK

Select Yes if you agree to trust the development certificate.

See Trust the ASP.NET Core HTTPS development certificate for more information

  • From Visual Studio, press Opt-Cmd-Return to run without the debugger. Alternatively, navigate to the menu bar and go to Run>Start Without Debugging.

    Visual Studio starts Kestrel, launches a browser, and navigates to http://localhost:5001.

Examine the project files

Here's an overview of the main project folders and files that you'll work with in later tutorials.

Pages folder

Contains Razor pages and supporting files. Each Razor page is a pair of files:

  • A .cshtml file that has HTML markup with C# code using Razor syntax.
  • A .cshtml.cs file that has C# code that handles page events.

Supporting files have names that begin with an underscore. For example, the _Layout.cshtml file configures UI elements common to all pages. This file sets up the navigation menu at the top of the page and the copyright notice at the bottom of the page. For more information, see Layout in ASP.NET Core.

wwwroot folder

Contains static assets, like HTML files, JavaScript files, and CSS files. For more information, see Static files in ASP.NET Core.

appsettings.json

Contains configuration data, like connection strings. For more information, see Configuration in ASP.NET Core.

Program.cs

Contains the entry point for the app. For more information, see .NET Generic Host in ASP.NET Core.

Startup.cs

Contains code that configures app behavior. For more information, see App startup in ASP.NET Core.

Next steps

This is the first tutorial of a series that teaches the basics of building an ASP.NET Core Razor Pages web app.

For a more advanced introduction aimed at developers who are familiar with controllers and views, see Introduction to Razor Pages.

At the end of the series, you'll have an app that manages a database of movies.

View or download sample code (how to download).

In this tutorial, you:

  • Create a Razor Pages web app.
  • Run the app.
  • Examine the project files.

At the end of this tutorial, you'll have a working Razor Pages web app that you'll build on in later tutorials.

Visual

Prerequisites

  • Visual Studio 2019 16.4 or later with the ASP.NET and web development workload

The Visual Studio Code instructions use the .NET Core CLI for ASP.NET Core development functions such as project creation. You can follow these instructions on any platform (macOS, Linux, or Windows) and with any code editor. Minor changes may be required if you use something other than Visual Studio Code. For more information on installing Visual Studio Code on macOS, see Visual Studio Code on macOS.

Visual Studio Code 2019

Create a Razor Pages web app

  • From the Visual Studio File menu, select New > Project.

  • Create a new ASP.NET Core Web Application and select Next.

  • Name the project RazorPagesMovie. It's important to name the project RazorPagesMovie so the namespaces will match when you copy and paste code.

  • Select ASP.NET Core 3.1 in the dropdown, Web Application, and then select Create.

The following starter project is created:

  • Open the integrated terminal.

  • Change to the directory (cd) which will contain the project.

  • Run the following commands:

    • The dotnet new command creates a new Razor Pages project in the RazorPagesMovie folder.
    • The code command opens the RazorPagesMovie folder in the current instance of Visual Studio Code.
  • After the status bar's OmniSharp flame icon turns green, a dialog asks Required assets to build and debug are missing from 'RazorPagesMovie'. Add them? Select Yes.

    A .vscode directory, containing launch.json and tasks.json files, is added to the project's root directory.

  • Select File > New Solution.

  • In Visual Studio for Mac earlier than version 8.6, select .NET Core > App > Web Application > Next. In version 8.6 or later, select Web and Console > App > Web Application > Next.

  • In the Configure the new Web Application dialog:

    • Confirm that Authentication is set to No Authentication.
    • If presented an option to select a Target Framework, select the latest 3.x version.

    Select Next.

  • Name the project RazorPagesMovie, and then select Create.

Run the app

  • Press Ctrl+F5 to run without the debugger.

    Visual Studio displays the following dialog:

    Select Yes if you trust the IIS Express SSL certificate.

    The following dialog is displayed:

    Select Yes if you agree to trust the development certificate.

    For information on trusting the Firefox browser, see Firefox SEC_ERROR_INADEQUATE_KEY_USAGE certificate error.

    Visual Studio starts IIS Express and runs the app. The address bar shows localhost:port# and not something like example.com. That's because localhost is the standard hostname for the local computer. Localhost only serves web requests from the local computer. When Visual Studio creates a web project, a random port is used for the web server.

  • Trust the HTTPS development certificate by running the following command:

    The preceding command doesn't work on Linux. See your Linux distribution's documentation for trusting a certificate.

    The preceding command displays the following dialog:

  • Select Yes if you agree to trust the development certificate.

    See Trust the ASP.NET Core HTTPS development certificate for more information.

For information on trusting the Firefox browser, see Firefox SEC_ERROR_INADEQUATE_KEY_USAGE certificate error.

  • Press Ctrl-F5 to run without the debugger.

    Visual Studio Code starts Kestrel, launches a browser, and navigates to http://localhost:5001. The address bar shows localhost:port# and not something like example.com. That's because localhost is the standard hostname for local computer. Localhost only serves web requests from the local computer.

Visual Studio for Mac displays the following popup:

Select Yes if you trust the development certificate.

The following dialog is displayed:

Enter your password and select OK

Select Yes if you agree to trust the development certificate.

See Trust the ASP.NET Core HTTPS development certificate for more information

  • From Visual Studio, press Opt-Cmd-Return to run without the debugger. Alternatively, navigate to the menu bar and go to Run>Start Without Debugging.

    Visual Studio starts Kestrel, launches a browser, and navigates to http://localhost:5001.

Examine the project files

Here's an overview of the main project folders and files that you'll work with in later tutorials.

Pages folder

Download Vs Code For Windows 10

Contains Razor pages and supporting files. Each Razor page is a pair of files:

  • A .cshtml file that has HTML markup with C# code using Razor syntax.
  • A .cshtml.cs file that has C# code that handles page events.

Supporting files have names that begin with an underscore. For example, the _Layout.cshtml file configures UI elements common to all pages. This file sets up the navigation menu at the top of the page and the copyright notice at the bottom of the page. For more information, see Layout in ASP.NET Core.

wwwroot folder

Contains static files, like HTML files, JavaScript files, and CSS files. For more information, see Static files in ASP.NET Core.

appSettings.json

Contains configuration data, like connection strings. For more information, see Configuration in ASP.NET Core.

Program.cs

Contains the entry point for the program. For more information, see .NET Generic Host in ASP.NET Core.

Startup.cs

Contains code that configures app behavior. For more information, see App startup in ASP.NET Core.

Next steps

This is the first tutorial of a series. The series teaches the basics of building an ASP.NET Core Razor Pages web app.

Microsoft Visual Editor Download

For a more advanced introduction aimed at developers who are familiar with controllers and views, see Introduction to Razor Pages.

At the end of the series, you'll have an app that manages a database of movies.

View or download sample code (how to download).

In this tutorial, you:

  • Create a Razor Pages web app.
  • Run the app.
  • Examine the project files.

At the end of this tutorial, you'll have a working Razor Pages web app that you'll build on in later tutorials.

Prerequisites

  • Visual Studio 2019 with the ASP.NET and web development workload

Warning

If you use Visual Studio 2017, see dotnet/sdk issue #3124 for information about .NET Core SDK versions that don't work with Visual Studio.

The Visual Studio Code instructions use the .NET Core CLI for ASP.NET Core development functions such as project creation. You can follow these instructions on any platform (macOS, Linux, or Windows) and with any code editor. Minor changes may be required if you use something other than Visual Studio Code.

Create a Razor Pages web app

  • From the Visual Studio File menu, select New > Project.

  • Create a new ASP.NET Core Web Application and select Next.

  • Name the project RazorPagesMovie. It's important to name the project RazorPagesMovie so the namespaces will match when you copy and paste code.

  • Select ASP.NET Core 2.2 in the dropdown, Web Application, and then select Create.

The following starter project is created:

  • Open the integrated terminal.

  • Change to the directory (cd) which will contain the project.

  • Run the following commands:

    • The dotnet new command creates a new Razor Pages project in the RazorPagesMovie folder.
    • The code command opens the RazorPagesMovie folder in the current instance of Visual Studio Code.
  • After the status bar's OmniSharp flame icon turns green, a dialog asks Required assets to build and debug are missing from 'RazorPagesMovie'. Add them? Select Yes.

    A .vscode directory, containing launch.json and tasks.json files, is added to the project's root directory.

  • Select File > New Solution.
  • In Visual Studio for Mac earlier than version 8.6, select .NET Core > App > Web Application > Next. In version 8.6 or later, select Web and Console > App > Web Application > Next.

  • In the Configure the new Web Application dialog:

    • Confirm that Authentication is set to No Authentication.
    • If presented an option to select a Target Framework, select the latest 2.x version.

    Select Next.

  • Name the project RazorPagesMovie, and then select Create.

Run the app

  • Press Ctrl+F5 to run without the debugger.

    Launching the app with Ctrl+F5 (non-debug mode) allows you to make code changes, save the file, refresh the browser, and see the code changes. Many developers prefer to use non-debug mode to quickly launch the app and view changes.

    Visual Studio displays the following dialog:

    Select Yes if you trust the IIS Express SSL certificate.

    The following dialog is displayed:

    Select Yes if you agree to trust the development certificate.

    For information on trusting the Firefox browser, see Firefox SEC_ERROR_INADEQUATE_KEY_USAGE certificate error.

    Visual Studio starts IIS Express and runs the app. The address bar shows localhost:port# and not something like example.com. That's because localhost is the standard hostname for the local computer. Localhost only serves web requests from the local computer. When Visual Studio creates a web project, a random port is used for the web server.

  • On the app's home page, select Accept to consent to tracking.

    This app doesn't track personal information, but the project template includes the consent feature in case you need it to comply with the European Union's General Data Protection Regulation (GDPR).

    The following image shows the app after consent to tracking is provided:

  • Trust the HTTPS development certificate by running the following command:

    The preceding command doesn't work on Linux. See your Linux distribution's documentation for trusting a certificate.

    The preceding command displays the following dialog:

  • Select Yes if you agree to trust the development certificate.

    See Trust the ASP.NET Core HTTPS development certificate for more information.

For information on trusting the Firefox browser, see Firefox SEC_ERROR_INADEQUATE_KEY_USAGE certificate error.

  • Press Ctrl+F5 to run without the debugger.

    Launching the app with Ctrl+F5 (non-debug mode) allows you to make code changes, save the file, refresh the browser, and see the code changes. Many developers prefer to use non-debug mode to quickly launch the app and view changes.

    Visual Studio Code starts Kestrel, launches a browser, and goes to http://localhost:5001. The address bar shows localhost:port# and not something like example.com. That's because localhost is the standard hostname for the local computer. Localhost only serves web requests from the local computer.

  • On the app's home page, select Accept to consent to tracking.

    This app doesn't track personal information, but the project template includes the consent feature in case you need it to comply with the European Union's General Data Protection Regulation (GDPR).

    The following image shows the app after you give consent to tracking:

Visual Studio for Mac displays the following popup:

Select Yes if you trust the development certificate.

The following dialog is displayed:

Enter your password and select OK

Select Yes if you agree to trust the development certificate.

See Trust the ASP.NET Core HTTPS development certificate for more information

  • Press Cmd-Opt-F5 to run without the debugger.

    Launching the app with Cmd+Opt+F5 (non-debug mode) allows you to make code changes, save the file, refresh the browser, and see the code changes. Many developers prefer to use non-debug mode to quickly launch the app and view changes.

    Visual Studio starts Kestrel, launches a browser, and goes to http://localhost:5001.

  • On the app's home page, select Accept to consent to tracking.

    This app doesn't track personal information, but the project template includes the consent feature in case you need it to comply with the European Union's General Data Protection Regulation (GDPR).

    The following image shows the app after consent to tracking is provided:

Examine the project files

Here's an overview of the main project folders and files that you'll work with in later tutorials.

Pages folder

Contains Razor pages and supporting files. Each Razor page is a pair of files:

  • A .cshtml file that has HTML markup with C# code using Razor syntax.
  • A .cshtml.cs file that has C# code that handles page events.

Supporting files have names that begin with an underscore. For example, the _Layout.cshtml file configures UI elements common to all pages. This file sets up the navigation menu at the top of the page and the copyright notice at the bottom of the page. For more information, see Layout in ASP.NET Core.

Razor Pages are derived from PageModel. By convention, the PageModel-derived class is named <PageName>Model.

wwwroot folder

Contains static files, like HTML files, JavaScript files, and CSS files. For more information, see Static files in ASP.NET Core.

Visual Studio Code 2019 Python

appSettings.json

Contains configuration data, like connection strings. For more information, see Configuration in ASP.NET Core.

Program.cs

Visual Studio Code 2019 Offline Installer

Contains the entry point for the program. For more information, see .NET Generic Host in ASP.NET Core.

Startup.cs

Contains code that configures app behavior, such as whether it requires consent for cookies. For more information, see App startup in ASP.NET Core.

Additional resources

Next steps

eBook Details:

  • Paperback: 386 pages
  • Publisher: WOW! eBook (January 15, 2021)
  • Language: English
  • ISBN-10: 1800203527
  • ISBN-13: 978-1800203525

eBook Description:

Visual Studio Code 2019 For Mac

Visual Studio 2019 Tricks and Techniques: Harness the full power of the Visual Studio IDE to take your coding skills to the next level by learning about IDE productivity practices and exclusive techniques

Visual Studio 2019 (VS 2019) and Visual Studio Code (VS Code) are powerful professional development tools that help you to develop applications for any platform with ease. Whether you want to create web, mobile, or desktop applications, Microsoft Visual Studio is your one-stop solution. This book demonstrates some of the most sophisticated capabilities of the tooling and shows you how to use the integrated development environment (IDE) more efficiently to be more productive.

Visual Studio 2020 Download

You’ll begin by gradually building on concepts, starting with the basics. The introductory chapters cover shortcuts, snippets, and numerous optimization tricks, along with debugging techniques, source control integration, and other important IDE features that will help you make your time more productive. With that groundwork in place, more advanced concepts such as the inner workings of project and item templates are covered. You will also learn how to write quality, secure code more efficiently as well as discover how certain Visual Studio features work ‘under the hood’.

  • Understand the similarities and differences between Visual Studio 2019 (VS 2019) and Visual Studio Code (VS Code)
  • Get to grips with numerous keyboard shortcuts to improve efficiency
  • Discover IDE tips and tricks that make it easier to write code
  • Experiment with code snippets that make it easier to write repeating code patterns
  • Find out how to customize project and item templates with the help of hands-on exercises
  • Use Visual Studio extensions for ease and improved productivity
  • Delve into Visual Studio’s behind the scene operations

By the end of this Visual Studio 2019 Tricks and Techniques book, you’ll have learned how to write more secure code faster than ever using your knowledge of the extensions and processes that make developing successful solutions more enjoyable and repeatable.