1. Modify Program.cs code and register as Windows Service
If you do not register builder.Host.UseWindowsService(); Installing as a window service will start an error
Install NuGet packages
Microsoft.Extensions.Hosting.WindowsServices
Program.cs code
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Host.UseWindowsService();
builder.WebHost.UseUrls("http://*:5010");
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
2. Publish the project
1. In the form of a folder
2. Select the corresponding platform when the target is running (this Coder is: winx-64)
3. Folder option: delete all existing files before publishing
3. Deploy to IIS
1. Need to install Hosting Bundle IIS runtime support (ASP.NET Core Module v2)
2. IIS deployment project
Official version address: https://dotnet.microsoft.com/download/dotnet
.NET 6.0 address: https://dotnet.microsoft.com/zh-cn/download/dotnet/6.0
4. Deploy with windows and install windows services
1. Install win service: sc create "windows service name" binPath= (space) "published project path.exe"
For example: sc create "PDD.ManageMent" binPath="D:\PDD.ManageMent.exe"
2. Uninstall win service: sc delete "PDD.ManageMent"
command prompt, run as administrator
start win service