Visual Studio For Mac Asp.net

Viewed 381 times
  1. Visual Studio For Mac Asp.net 4.5
  2. Microsoft Visual Studio For Mac
  • I'm working as frontend developer in a company which uses asp.net for its website. I usually work on mac and I need to setup my localhost to work on the website, but something's wrong with the project.
  • I use Microsoft Virtual Server to host my development environments. These environments run in the background and I can use Remote Desktop to access them in full screen mode.

I am developing an asp.net application on macOS with Visual Studio for Mac, and I can specify a custom run configuration.

I Installed Visual Studio 2017 Community for Mac yesterday and tried it out. Not so good, the toolbox is totally empty and to switch between code view and design view does not work.

There seems to be no way to specify a run profile, where all arguments and settings in the custom configuration are saved, instead of reentering command line arguments every time.

Is there a way to do this easily in VS for Mac? Or is that feature not available yet...

Richard DuerrRichard Duerr
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.

Browse other questions tagged asp.netmacosvisual-studioconfigurationsave or ask your own question.

-->

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.

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

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 3.0 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.
  • Select .NET Core > App > Web Application > Next.

  • In the Configure your new ASP.NET Core Web API dialog, set the Target Framework to .NET Core 3.0.

  • Name the project RazorPagesMovie, and then select Create.

Open the project

From Visual Studio, select File > Open, and then select the RazorPagesMovie.csproj file.

Run the app

Asp.net
  • 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.

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

    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.

  • 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.

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

  • The preceding command displays the following output:

  • Enter the admin username and password if prompted. The certificate will now be installed and trusted.

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

  • Press Alt-Cmd-Enter 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 contains HTML markup with C# code using Razor syntax.
  • A .cshtml.cs file that contains 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, such as HTML files, JavaScript files, and CSS files. For more information, see Static files in ASP.NET Core.

appSettings.json

Contains configuration data, such as 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.

Startup.cs

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

Next steps

Advance to the next tutorial in the series:

This is the first tutorial of a series. The series 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.

Asp.net

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.

From a terminal, run the following command:

The preceding commands use the .NET Core CLI to create a Razor Pages project.

Open the project

From Visual Studio, select File > Open, and then select the RazorPagesMovie.csproj file.

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.

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

    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 you give consent to tracking:

  • 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.

  • 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.

  • 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:

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

  • The preceding command displays the following output:

  • Enter the admin username and password if prompted. The certificate will now be installed and trusted.

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

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

    Visual Studio starts Kestrel, launches a browser, and navigates 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 you give consent to tracking:

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 contains HTML markup with C# code using Razor syntax.
  • A .cshtml.cs file that contains 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, such as HTML files, JavaScript files, and CSS files. For more information, see Static files in ASP.NET Core.

appSettings.json

Contains configuration data, such as 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.

Startup.cs

Visual Studio For Mac Asp.net 4.5

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

Microsoft Visual Studio For Mac

Advance to the next tutorial in the series: