Windows Deployment of NCF Site
To make it more convenient for everyone to seamlessly use NCF, here is how to publish the latest version of the site.
No matter how cool and practical your website is in the development environment, it ultimately needs to be tested and deployed. Therefore, using a cloud server for testing and production environments is essential.
This section mainly helps you eliminate obstacles in the publishing and deployment process, allowing you to deploy the site from the development environment to the testing and production environments smoothly, like shifting gears in an automatic car.
Ultimately, you should focus on the core business and not let these auxiliary tasks take up too much of your time.
Let's talk about how to publish.
Steps
- Rebuild
It will be displayed in the lower left corner of the Visual Studio tool.
This indicates that everything has been successfully generated. Then click publish.
When choosing the publishing method, select Folder.
- Configure parameters before publishing
As shown in the figure:
Configuration: Choose Debug or Release, or others.
Target Framework: Different versions of .NET Core, net6.0/7.0, etc.
Deployment Mode: Framework-dependent | Self-contained (You can learn about the differences between the two deployment modes).
Target Runtime: You can choose portable or specified runtime environments, such as win-x64, linux, etc.
- Publish
After the previous step, click Save.
Then click Publish.
After publishing, check these two key points to confirm the publication was successful.
Enter the directory of the generated files.
- Compress files
Select all files, right-click and compress them into a zip file.
- Copy files to the server
This is just CTRL+C (copy), CTRL+V (paste), and paste them onto the server.
- Create an IIS site
First, open IIS.
Add a website.
Focus on the areas in the red box.
This is the created site.
- Configure IIS to access .NET Core site information
Creating a site will also generate an application.
Since the project we are deploying is .NET Core, this needs to be modified.
Modify according to this configuration. After modification, select Advanced Settings.
After opening, configure the parameters to the values in the red box.
First stop the application, then start it.
If there is an error when starting, keep trying until it starts successfully.
Common errors are as follows:
The literal meaning is that the corresponding versions of Microsoft.NetCore.App and Microsoft.AspNetCore.App cannot be found.
The official error documentation is: https://learn.microsoft.com/aspnet/core/test/troubleshoot-azure-iis?view=aspnetcore-7.0
<img src="./images/deploy-website-run-01.png">
Let's run the following command
```csharp
8. Run the site (this process may encounter many strange issues), and the handling methods vary depending on the issue.
```csharp
HTTP Error 500.31 - ANCM Failed to Find Native Dependencies
Common solutions to this issue:
The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found.
dotnet --info
The result shows
<img src="./images/deploy-website-run-02.png">
The above figure is crucial; you need to understand whether the installed versions are being used by IIS. If they do not match, errors will occur.
Look at the figure below; it shows an adjusted environment.
<img src="./images/deploy-website-run-03.png">
Some of you might ask, how do we know if the SDK version and Host version are correct?
We go to the place to download the .NET Core SDK: https://dotnet.microsoft.com/download/dotnet/6.0
<img src="./images/deploy-website-run-04.png">
Mainly observe the content in the red box to understand.
<img src="./images/deploy-website-run-05.png">
If the .NET Core SDK version and Host version shown by dotnet --info match, then the basic configuration is complete. But it doesn't end here; it might still report error 500.31. At this point, you need to troubleshoot based on the prompt information. For example,
Windows log troubleshooting, enter eventvwr in the DOS window to display, as shown in the error mark below, find the ones related to IIS and handle them according to the prompts.
<img src="./images/deploy-website-run-06.png">
For example:
Could not find 'aspnetcorev2_inprocess.dll'. Exception message:
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '6.0.0' was not found.
- The following frameworks were found:
3.1.3 at [C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App]
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=6.0.0&arch=x86&rid=win10-x86
It means that version 6.0.0 of Microsoft.NETCore.App is not installed, and the installation address is provided below.
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=6.0.0&arch=x86&rid=win10-x86
After installation, you can access the site. If there are still errors, continue to fix them according to the prompts until there are no IIS errors.
The final presentation is the information of the website we see. If there is anything unclear, you can directly ask me in the community group.
<img src="./images/deploy-website-run-07.png">