本文介绍了AssemblyInstaller中的ServiceType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过

这是代码段.

private static AssemblyInstaller GetInstaller()
{
    AssemblyInstaller installer = new AssemblyInstaller(
        typeof(YourServiceType).Assembly, null);
    installer.UseNewContext = true;
    return installer;
}

我不知道这里的"YourServiceType"是什么. MSDN

I don't know what is the "YourServiceType" here. The syntax of AssemblyInstaller Constructor in MSDN is

public AssemblyInstaller(
    Assembly assembly,
    string[] commandLine
)

更新:

疯狂的事情是,如果在bin \ debug文件夹下运行命令"MyApplication.exe -install",则无法启动该服务.但是,如果处于调试模式,则将参数放在项目属性的启动选项"中.没关系.为什么?我确实按照示例的步骤进行操作.我将"StartType"设置为自动".

The wild thing is that I can't start the service if running the command "MyApplication.exe -install" under the folder bin\debug.However if in debug mode, which I put the argument in "Start Options" of the project property. It is okay. Why? I did following the steps at example. I set the "StartType" as "Automatic".

推荐答案

YourServiceType 是Windows服务的类型名称.如果您从头开始遵循我的指示,那么您最初是使用Visual Studio提供的模板创建服务的.默认情况下,这为您提供了一个名为 Service1 之类的服务类.如果您尚未更改类的名称,请使用 Service1 .否则,请使用您将其更改为的名称.

YourServiceType is the type name of your Windows service. If you've followed my directions from scratch, then you originally created your service using the template provided by Visual Studio. By default, this gives you a service class named something like Service1. If you have not changed the name of your class, use Service1. Otherwise, use the name you changed it to.

private static AssemblyInstaller GetInstaller()
{
    AssemblyInstaller installer = new AssemblyInstaller(
        typeof(Service1).Assembly, null);
    installer.UseNewContext = true;
    return installer;
}

这篇关于AssemblyInstaller中的ServiceType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 10:36