【问题标题】:VS2013 Windows Service - How to make installer?VS2013 Windows Service - 如何制作安装程序?
【发布时间】:2014-04-08 13:10:20
【问题描述】:

我写了一个 Windows 服务。

我现在想将它打包到一个安装程序中。

我已经使用了 VS2013 x86 Native Tools 命令提示符,然后使用了命令:

要安装它:

installutil httpapiservice.exe

要卸载它:

installutil httpapiservice.exe /u

这非常有效。我可以在“服务”中看到新服务并停止和启动它没有问题。

然后我继续右键单击该项目并选择“发布”,它会生成一个 setup.exe

但是,当我运行 setup.exe 时,我可以看到它“下载和解压缩”文件。看起来它正在安装,但“服务”中没有显示任何内容

谁能告诉我我做得对吗?

谢谢

【问题讨论】:

标签: c# visual-studio


【解决方案1】:

您需要将安装项目添加到您的解决方案中以构建安装程序可执行文件。

不幸的是,Microsoft 从 Visual Studio 2012 开始删除了他们的设置项目模板,这本来可以完成这项工作。

这意味着您被其中一种替代方案所困扰,这些替代方案要么功能较少、难以设置,要么价格昂贵。

注意 - 向下滚动到 EDIT 3 以获得我推荐的解决方案。这篇文章的其余部分只是强调替代方案。

如果您喜欢免费路线,您可以将 InstallShield Limited Edition 添加到 Visual Studio,并使用它为您的解决方案创建安装项目。它适用于最新版本的 Windows 服务设置项目,但通常被认为是非常垃圾和有限的。以下是相关说明:link

WiX 是一个免费的开源替代品,功能更丰富,但设置起来很棘手。

编辑 -

这是一篇描述如何使用 WiX 创建安装项目的文章:http://www.schiffhauer.com/wix-template-for-installing-a-windows-service/

编辑 2 -

截至今天(2014 年 4 月 22 日),Microsoft 已将 Visual Studio 2013 中的安装项目恢复为 Visual Studio 扩展 - 请参阅 this post

我自己没有尝试过,但它大概和 VS2010 安装项目一样,学习起来并不难(并且互联网上有很多帮助)我绝对建议你试试这个正在创建您的安装程序!

编辑 3(2016 年 4 月)-
我强烈建议您使用 Visual Studio Installer Projects Extension(如上述编辑中所述)为您的 Windows 服务(以及其他程序)创建简单的安装程序。它创建的安装程序很简单,但对于简单或小型项目来说足够专业。

Visual Studio 2013 的扩展名是here
Visual Studio 2015 的扩展名是 here
Visual Studio 2017 的扩展名是here

描述如何使用旧的 VS2010 安装项目为 Windows 服务创建安装项目的文章是 here。虽然这是一篇旧文章,但它可以直接应用于上面链接的新安装程序项目扩展。 (感谢 EbbnFlow 提供链接)

【讨论】:

  • 哇。这听起来比一开始写代码要难。大声笑:)
  • InstallShield LE 使用起来并不难,只是功能有限。不过,假设您不需要过多地自定义安装,或者在设置过程中选择服务用户,这对您来说可能就足够了。试试看!替代方案:WiX 的学习曲线相当陡峭,但您或许可以为 Windows 服务设置项目找到一个预先编写的模板,让您的生活更轻松
  • 支持提及 Visual Studio 2013 扩展。
  • @oscilatingcretin 手头没有链接,但我怀疑这是因为他们 (a) 懒得维护它,更有可能 (b) 从 Flexera (Installshield开发人员)希望他们现在已经看到了曙光,并意识到他们不应该以牺牲开发人员社区为代价来满足商业合作伙伴
  • @CSS 我愿意。不过它确实有效。我自己已经验证它可以与 VS 2013 安装项目一起使用。
【解决方案2】:

我建议观看此视频。 https://www.youtube.com/watch?v=cp2aFNtcZfk

经过验证

【讨论】:

    【解决方案3】:

    我最终压缩了软件并包含 installutil.exe,并简单地向客户说明必须安装和卸载。

    似乎效果很好。

    HTH

    【讨论】:

    • 我想你可以更进一步,编写一个带有 [Install] 和 [Uninstall] 按钮的小 winforms 应用程序来执行正确的命令字符串。
    • 这适用于 2013 年安装项目。 support.microsoft.com/en-us/kb/816169
    【解决方案4】:

    您似乎想使用 ClickOnce(发布)来安装服务。这不可能没有麻烦,但您可以尝试按照this answer 中的说明进行操作。

    【讨论】:

      【解决方案5】:

      这些官方 Microsoft 扩展为 Visual Studio 2013 中的 Visual Studio 安装程序项目提供支持https://visualstudiogallery.msdn.microsoft.com/9abe329c-9bba-44a1-be59-0fbf6151054d 和 Visual Studio 2015 https://visualstudiogallery.msdn.microsoft.com/f1cc3f3e-c300-40a7-8797-c509fb8933b9

      通过这些扩展和上一篇文章中的视频,我能够在 Visual Studio Community 2015 中为 Windows 服务创建一个安装项目。

      不要忘记为安装和卸载添加自定义操作(如视频中所述),也不要忘记将安装程序类添加到您的服务项目中,以便在系统 --> 服务下正确安装您的服务.

      我已经通过代码添加了 serviceProcessInstaller 和 serviceInstaller-component 并进行了如下配置:

      public XxxServiceInstaller()
      {
          InitializeComponent();
      
          ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
          ServiceInstaller serviceInstaller = new ServiceInstaller();
      
          // Service Account Information
          serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
          serviceProcessInstaller.Username = null;
          serviceProcessInstaller.Password = null;
      
          // Service Information
          serviceInstaller.ServiceName = "your service name";
          serviceInstaller.DisplayName = "your service display name";
          serviceInstaller.StartType = ServiceStartMode.Manual; // or automatic
      
          this.Installers.Add(serviceProcessInstaller);
          this.Installers.Add(serviceInstaller);
      
          this.AfterInstall += new InstallEventHandler(ProdSSSyncServiceInstaller_AfterInstall);
      }
      
      void XxxServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
      {
          ServiceController sc = new ServiceController("your service name");
          // start immediately
          sc.Start();
      }
      

      【讨论】:

        猜你喜欢
        • 2016-12-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多