过去我使用过这些课程安装人员 https://learn.microsoft.com/en-us/dotnet/api/system.configuration.install.installer?view=netframework-4.8, 服务安装程序 https://learn.microsoft.com/en-us/dotnet/api/system.serviceprocess.serviceinstaller?view=netframework-4.8 and 服务进程安装程序 https://learn.microsoft.com/en-us/dotnet/api/system.serviceprocess.serviceprocessinstaller?view=netframework-4.8使我的应用程序可自行安装。
我只得跑InstallUtil.exe MyApp
将应用程序安装为 Windows 服务。
但我在 DotNet5 上找不到这些类。
他们不会被移植吗?
还有其他方法可以替代它们吗?
谁能向我指出一些有关如何实现这一目标的文档?
下面是一个关于过去如何使用这些类的示例:
[RunInstaller(true)]
public class MyServiceInstaller : Installer
{
private string serviceName = "MyApp";
public MyServiceInstaller()
{
var processInstaller = new ServiceProcessInstaller();
var serviceInstaller = new ServiceInstaller();
processInstaller.Account = ServiceAccount.LocalSystem;
processInstaller.Username = null;
processInstaller.Password = null;
serviceInstaller.ServiceName = serviceName;
serviceInstaller.DisplayName = serviceName;
serviceInstaller.StartType = ServiceStartMode.Automatic;
this.Installers.Add(processInstaller);
this.Installers.Add(serviceInstaller);
this.Committed += new InstallEventHandler(MyServiceInstaller_Committed);
}
void MyServiceInstaller_Committed(object sender, InstallEventArgs e)
{
var controller = new ServiceController(serviceName);
controller.Start();
}
}
我们可以在 Assembly Core .System.ServiceProcess nuget 包中找到这些类/库,该包与 .Net 5、6 和最新版本兼容。在 Visual Studio 中所需的项目上安装此 Nuget 包。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)