首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >安装在Visual Studio中创建的Windows服务

安装在Visual Studio中创建的Windows服务
EN

Stack Overflow用户
提问于 2011-10-28 04:41:30
回答 7查看 153.3K关注 0票数 143

当我在Visual Studio2010中创建一个新的Windows service时,我收到一条消息,指出要使用InstallUtil和net start来运行该服务。

我尝试了以下步骤:

TestService

  • Build

  • 创建新项目文件->新的->项目-> Windows项目名称:"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe“TestService.exe

  • Run项目原样(Service1构造函数,OnStart,OnStop)

  • 打开命令提示符,运行Windows net start Windows

步骤4输出

运行事务处理安装的

开始安装的安装阶段。

查看C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\TestService\obj\x86\Debug\TestService.exe程序集进度的日志文件内容。

该文件位于C:\Users\myusername\Documents\Visual Studio2010\Projects\Tes tService\TestService\obj\x86\Debug\TestService.InstallLog.

安装程序集C:\Users\myusername\Documents\Visual Studio2010\Projects\TestS ervice\TestService\obj\x86\Debug\TestService.exe'.

受影响的参数包括:

logtoconsole =

日志文件= C:\Users\myusername\Documents\Visual Studio2010\Projects\TestService\T estService\obj\x86\Debug\TestService.InstallLog

汇编路径= C:\Users\myusername\Documents\Visual Studio2010\Projects\TestServ ice\TestService\obj\x86\Debug\TestService.exe

在C:\Users\myusername\Documents\Visual Studio2010\Projects\TestService\TestSe rvice\obj\x86\Debug\TestService.exe程序集中找不到具有RunInstallerAttribute.Yes属性的公共安装程序。

安装阶段已成功完成,提交阶段正在开始。

查看C:\Users\myusername\Documents\Visual Studio 2010\Projects\TestService\TestService\obj\x86\Debug\TestService.exe程序集进度的日志文件内容。

该文件位于C:\Users\myusername\Documents\Visual Studio2010\Projects\Tes tService\TestService\obj\x86\Debug\TestService.InstallLog.

提交程序集'C:\Users\myusername\Documents\Visual Studio2010\Projects\TestS ervice\TestService\obj\x86\Debug\TestService.exe'.

受影响的参数包括:

logtoconsole =

日志文件= C:\Users\myusername\Documents\Visual Studio2010\Projects\TestService\T estService\obj\x86\Debug\TestService.InstallLog

汇编路径= C:\Users\myusername\Documents\Visual Studio2010\Projects\TestServ ice\TestService\obj\x86\Debug\TestService.exe

在C:\Users\myusername\Documents\Visual Studio2010\Projects\TestService\TestSe rvice\obj\x86\Debug\TestService.exe程序集中找不到具有RunInstallerAttribute.Yes属性的公共安装程序。

删除InstallState文件,因为没有安装程序。

提交阶段已成功完成。

事务处理的安装已完成。

步骤5输出

服务名称无效。

键入NET HELPMSG 2185可获得更多帮助。

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2011-10-28 04:45:56

您需要在设计器中打开Service.cs文件,右键单击它,然后选择菜单选项“添加安装程序”。

它不会开箱即装...首先需要创建installer类。

关于服务安装程序的一些参考:

How to: Add Installers to Your Service Application

相当古老..。但这就是我要说的:

Windows Services in C#: Adding the Installer (part 3)

通过这样做,将自动创建一个ProjectInstaller.cs。然后,您可以双击它,进入设计器,并配置组件:

  • serviceInstaller1具有服务本身的属性: important.
  • serviceProcessInstaller1具有以下重要属性:DescriptionDisplayNameServiceNameStartTypeAccount是运行服务的帐户。

例如:

代码语言:javascript
复制
this.serviceProcessInstaller1.Account = ServiceAccount.LocalSystem;
票数 252
EN

Stack Overflow用户

发布于 2011-10-28 04:45:19

查看:

在C:\Users\myusername\Documents\Visual Studio2010\Projects\TestService\TestSe rvice\obj\x86\Debug\TestService.exe程序集中找不到具有RunInstallerAttribute.Yes属性的公共安装程序。

看起来您的代码中可能没有安装程序类。这是一个继承自Installer的类,它将告诉installutil如何将可执行文件作为服务安装。

附注:我在这里有我自己的小的自安装/可调试的Windows Service模板,您可以从其中复制代码或使用:Debuggable, Self-Installing Windows Service

票数 12
EN

Stack Overflow用户

发布于 2016-11-04 03:48:48

这里有一种替代的方法来制作安装程序并摆脱那个错误消息。而且,VS2015 express似乎没有“添加安装程序”菜单项。

您只需创建一个类,添加以下代码并添加引用System.Configuration.Install.dll即可。

代码语言:javascript
复制
using System.Configuration.Install;
using System.ServiceProcess;
using System.ComponentModel;


namespace SAS
{
    [RunInstaller(true)]
    public class MyProjectInstaller : Installer
    {
        private ServiceInstaller serviceInstaller1;
        private ServiceProcessInstaller processInstaller;

        public MyProjectInstaller()
        {
            // Instantiate installer for process and service.
            processInstaller = new ServiceProcessInstaller();
            serviceInstaller1 = new ServiceInstaller();

            // The service runs under the system account.
            processInstaller.Account = ServiceAccount.LocalSystem;

            // The service is started manually.
            serviceInstaller1.StartType = ServiceStartMode.Manual;

            // ServiceName must equal those on ServiceBase derived classes.
            serviceInstaller1.ServiceName = "SAS Service";

            // Add installer to collection. Order is not important if more than one service.
            Installers.Add(serviceInstaller1);
            Installers.Add(processInstaller);
        }
    }
}
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7922105

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档