Publish an ASP.NET Web App to an Azure VM from Visual Studio
This document describes how to publish an ASP.NET web application to an Azure virtual machine (VM) using the Microsoft Azure Virtual Machines publishing feature in Visual Studio 2017.
In order to use Visual Studio to publish an ASP.NET project to an Azure VM, the VM must be correctly set up.
Machine must be configured to run an ASP.NET web application and have WebDeploy installed.
The VM must have a DNS name configured. For more information, see Create a fully qualified domain name in the Azure portal for a Windows VM.
Publish your ASP.NET web app to the Azure VM using Visual Studio
The following section describes how to publish an existing ASP.NET web application to an Azure virtual machine.
Open your web app solution in Visual Studio 2017.
Right-click the project in Solution Explorer and choose Publish...
Use the arrow on the right of the page to scroll through the publishing options until you find Microsoft Azure Virtual Machines.
Select the Microsoft Azure Virtual Machines icon and select Publish.
Choose the appropriate account (with Azure subscription connected to your virtual machine).
- If you're signed in to Visual Studio, the account list is populated with all your authenticated accounts.
- If you are not signed in, or if the account you need is not listed, choose "Add an account..." and follow the prompts to log in.
Select the appropriate VM from the list of Existing Virtual Machines.
Populating this list can take some time.
Click OK to begin publishing.
When prompted for credentials, supply the username and password of a user account on the target VM that is configured with publishing rights (typically the admin username and password used when creating the VM).
Accept the security certificate.
Watch the Output window to check the progress of the publish operation.
If publishing is successful, a browser launches to open the URL of the newly published site.
You have now successfully published your web app to an Azure virtual machine.
Publish Page Options
After completing the publish wizard, the Publish page is opened in the document well with the new publishing profile selected.
To publish updates to your web application, select the Publish button on the Publish page.
- If prompted, enter username and password.
- Publishing begins immediately.
Modify publish profile settings
To view and modify the publish profile settings, select Settings....
Your settings should look something like this:
Save User name and Password
- To avoid providing authentication information every time you publish, you can populate the User name and Password fields and select the Save password box.
- Use the Validate Connection button to confirm that you have entered the right information.
Deploy to clean web server
If you want to ensure that the web server has a clean copy of the web application after each upload (and that no other files are left hanging around from a previous deployment), you can check the Remove additional files at destination checkbox in the Settings tab.
Warning: Publishing with this setting deletes all files that exist on the web server (wwwroot directory). Be sure you know the state of the machine before publishing with this option enabled.
Set up CI/CD for automated deployment to Azure VM
To set up a continuous delivery pipeline with Azure Pipelines, see Deploy to a Windows Virtual Machine.
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.