简体   繁体   中英

How to Deploy a Windows Service using Visual Studio 2017 Community

Working with VS2017 Community I have written a service that works on my local machine. I followed the instruction here: https://docs.microsoft.com/en-us/dotnet/framework/windows-services/walkthrough-creating-a-windows-service-application-in-the-component-designer

and installed it successfully using Installutil.exe (as per instructions in above link). All good.

I now want to deploy that across six servers in our organisation. In Microsoft's documentation about installing services ( https://docs.microsoft.com/en-us/dotnet/framework/windows-services/how-to-install-and-uninstall-services ) it says:

If you're a developer who wants to release a Windows Service that users can install and uninstall you should use InstallShield

and links to a page that applies to VS2012 (can't post any more links as my reputation<10)

I have downloaded and installed the "Microsoft Visual Studio 2017 Installer Projects" package, which allows me to create a Setup Project. When I run it, it installs the project output correctly (ie copies the exe & dll files to the correct folder in Program Files) but does not create the service.

There's a detailed post about deploying services on this site (question 9021075) but when I follow those instructions I get a 1001 error on Install.

All the documentation I can find refers to earlier versions of VS or the previous Installer package, so I'm not even certain if I can do it with the software I am using.

So, with VS2017 Community using Microsoft Visual Studio 2017 Installer Projects, how to I create a stand-alone Installer to deploy a service that works correctly when installed locally using InstallUtil?

Or can I use InstallUtil on the target machines? I think I'd need to install Visual Studio on them for that, which I'd prefer not to. Is there a quicker way?

I only have 6 servers to install this on, so even some manual work-around might do.

Thank you for the responses. I now have a solution. I found InstallUtil on the Target Server (in my case it was in C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319 but search will find it). I copied and added that to my project as content so when I now deploy it, I have InstallUtil in the same folder as my EXE.

To install, I run CMD as admin, cd to project folder and issue command:

installutil.exe myService.exe

This is a one-off task. Once the service is working, to update it I just need to stop it, upload the new myService.exe (& any DLLs) to overwrite the old ones and restart it again.

Further information about settings you're using for the serviceProcessInstaller1 and serviceInstaller1 files will be needed to debug this issue, as the 1001 error raised by the installer is a generic error.

An alternative way of doing this is to use Topshelf , which is a framework for hosting services written using the .NET framework. It simplifies the creation of services, allowing developers to create a simple console application that can be installed as a service using Topshelf . The reason for this is simple: It is far easier to debug a console application than a service. And once the application is tested and ready for production, Topshelf makes it easy to install the application as a service.

Alternatively, you could use InstallUtil.exe . It is part of the .NET Framework, so no need to install Visual Studio.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM