Introduction
This guide provides a comprehensive, step-by-step tutorial for deploying a .NET Core or Blazor application to an IIS website using a Plesk Publishing XML file in Visual Studio 2022. It also includes instructions for handling SSL errors that may arise during the publishing process within Visual Studio.
Prerequisites
- Visual Studio 2022 installed.
- Plesk Control Panel access with a hosting plan that includes IIS.
- Plesk Web Deploy Publishing XML file (located in your Plesk Control Panel Dashboard).
- .NET Core or Blazor application ready for deployment.
- Administrator credentials for Plesk.
Step-by-Step Guide
1. Prepare Your .NET Core or Blazor Application
Ensure your application runs correctly on your local machine. Thoroughly test the application before deploying it to ensure all functionality works as expected.
2. Obtain the Plesk Publishing XML File
- Log in to your Plesk account.
- Navigate to Websites & Domains.
- Select the domain you wish to deploy to.
- Click on Web Deploy Publishing Settings.
- Download the Plesk Publishing XML file. This file contains the deployment configuration settings needed for publishing.
3. Set Up the Publishing Profile in Visual Studio
- Open your project in Visual Studio 2022.
- In the Solution Explorer, right-click your project and select Publish.
- In the Publish window, choose Import Profile.
- Locate and import the Plesk Publishing XML file.
4. Configure Publish Settings
After importing the profile, configure the publish settings:
- Configuration: Choose Release for production deployment.
- Target Framework: Select the appropriate .NET version.
- Deployment Mode: Select Self-Contained if the required .NET runtime is not installed on the server; otherwise, select Framework-Dependent.
5. Certificate Errors When Publishing
The Web Deploy server awh-plesk1-win2022.adaptivewebhosting.com (port 8172) uses a publicly trusted Let's Encrypt certificate, so Visual Studio validates it without any changes. If publishing fails with a certificate error such as ERROR_CERTIFICATE_VALIDATION_FAILED:
- Open the
.pubxmlfile for your profile in theProperties\PublishProfilesfolder. - Check that
MSDeployServiceURLisawh-plesk1-win2022.adaptivewebhosting.com(orhttps://awh-plesk1-win2022.adaptivewebhosting.com:8172/msdeploy.axd) and not your own domain or an IP address. The certificate only covers the server name. - Only if you have to connect by IP address or another name, add
<AllowUntrustedCertificate>true</AllowUntrustedCertificate>inside the<PropertyGroup>tag. This skips the certificate check, so prefer the server name.
You do not need to install any server certificate into your computer's Trusted Root Certification Authorities store.
6. Publish Your Application
- In Visual Studio, go to the Publish tab.
- Click Publish to start the deployment process. Visual Studio will compile your application and deploy it to the selected IIS site.
7. Verify Deployment
After the deployment completes:
- Visit your website's URL in a browser.
- Verify that your application is running correctly and that all features are functioning as expected.
8. Troubleshooting Common Issues
-
Application Doesn't Start:
- Check the site logs for detailed error logs.
- Verify all necessary dependencies are installed on the server.
-
SSL Warnings:
- Publish to awh-plesk1-win2022.adaptivewebhosting.com (see step 5). The certificate does not cover your own domain name or an IP address.
-
500 Internal Server Error:
- Review your
web.configfile and ensure it matches the server environment setup.
- Review your
9. Best Practices
- Back-Up Regularly: Always back up your website and databases before deploying new changes.
Conclusion
Publishing a .NET Core or Blazor application to a Windows Server 2022 IIS website using a Plesk Web Deploy Publishing XML file in Visual Studio 2022 is straightforward when following these steps. Properly handling SSL errors and ensuring all settings are correct will result in a smooth deployment process.