aspnetcore/tutorials/publish-to-azure-webapp-using-vscode.md
With this tutorial, you'll learn how to create an ASP.Net Core MVC Application and deploy it within Visual Studio Code. The tutorial assumes familiarity with VS Code. For more information, see Getting started with VS Code. This tutorial will work on Windows, macOS, or Linux environments. Be sure to use the correct path separating characters (\ vs /) for your environment.
[!INCLUDE Azure App Service Preview Notice]
To troubleshoot an App Service deployment issue, see xref:test/troubleshoot-azure-iis.
Open the integrated terminal.
Set your working directory (cd) to the directory that will contain the project.
Run the following commands:
dotnet new mvc -o MyMVCapp
code -r MyMVCapp
For the preceding commands:
dotnet new mvc -o MyMVCapp
code -r MyMVCapp
MyMVCapp.csproj project file in Visual Studio Code.[!NOTE] If a dialog box appears with Required assets to build and debug are missing from 'MyMVCapp'. Add them?, select Yes.
A new ASP.NET Core MVC project is created in a MyMVCapp folder with a structure similar to the following:
appsettings.Development.json
appsettings.json
<DIR> bin
<DIR> Controllers
<DIR> Models
MyMVCapp.csproj
<DIR> obj
Program.cs
<DIR> Properties
<DIR> Views
<DIR> wwwroot
A .vscode folder will be created under the project structure. It will contain utility files to help you build and debug your ASP.NET Core web app.
Before deploying the app to Azure, make sure it is running properly on your local machine.
Open the integrated terminal (if needed).
Set up the a trusted HTTPS development certificate:
Run the following command:
dotnet run
The preceding command:
http://localhost:<port>, where <port> is the random port number set in Properties\launchSettings.json at project creation.The output shows messages similar to the following, indicating that the app is running and awaiting requests:
$ dotnet run
Building...
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:7064
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5119
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: D:\Src\MyMVCapp\
<kbd>Ctrl</kbd>+click the HTTPS URL in the output to test the web app in a browser. In the example above, the URL is https://localhost:7064.
Press <kbd>Ctrl</kbd>+<kbd>C</kbd> in the integrated terminal to shut down the web app after testing it.
In the integrated terminal, use the following command to generate a Release package in a folder located at bin/Publish:
dotnet publish -c Release -o ./bin/Publish
A new Publish subfolder will be created in the bin folder. This folder contains the files to be deployed to Azure.
:::image type="content" source="publish-to-azure-webapp-using-vscode/_static/publish-folder.png" alt-text="Publish folder structure" lightbox="publish-to-azure-webapp-using-vscode/_static/publish-folder.png":::
Leveraging the Azure App Service extension for Visual Studio Code, follow the steps below to publish the website directly to the Azure App Service.
If you don't have an existing Azure Web App resource to publish to, you must create one.
.NET 6 (LTS)). Do not select the ASP.NET runtime, which is for .NET Framework apps.Right click the bin\Publish folder and select Deploy to Web App... and follow the prompts.
Once the deployment is finished, click Browse Website to validate the deployment.
Once you click Browse Website, you'll navigate to it using your default browser:
[!TIP] You can repeat the above steps to redeploy the app to the same Azure Web App resource as needed. Be sure to run
dotnet publishagain before you deploy to Azure.