ClickOnce deploy a Windows Service? - c#

Is it possible to deploy a Windows Service using ClickOnce? If so, how do you achieve this?
Currently we have to use a Deployment project, and the installation process could be simplified greatly by using ClickOnce.

AFAIK you can't really use ClickOnce end-to-end to deploy a service; there are issues with both the file locations (ClickOnce installs into a user's profile) and installation (ClickOnce is largely side-effect free).
You can, however, write a service as an exe that can self-install/uninstall from the services list, like so; basically, you write it as as a console exe and handle some command line args, using AssemblyInstaller to [un]install from the current assembly. Another advantage is that the same approach can be used to help debugging, since you can run it from the command line.

I guess NO according to Choosing Between ClickOnce and Windows Installer

Instead of ClickOnce, I like to use the approach using Inno Setup, like in here https://stackoverflow.com/a/1450051/396200
You have more control over what and how will be copied and executed.
As Marc Gravell said in his answer, I create a exe that self install my service, and then use Inno Setup to pack and deploy it. After Inno setup installed, it automatically run the exe and then my exe install my service.

Related

Creating an single installer of a solution with WPF as start up project and depend on Windows Service

Asking similar question because no one answered previous question asked
I have a solution with a class library project, a WPF project (start up project) and a Windows Service project. I would like to create one installer so that when the user installs the application then both WPF (UI) and Windows service gets installed.
Most of the resources I found online only talk about one or another but not both. For example this:.
I checked some question on stackoverflow but either they are not answered by any one or vague answers like this question or this one.
Any suggestion how to achieve this?
I'm not an expert on various installer solutions, but yes, this can be done. I know because my project does it.
We've historically used InstallShield, but we are actively moving to InstallAware for reasons unrelated to this discussion. Frankly, I suspect any installer solution (e.g., InstallShield, InstallAware, Wix, etc.) could be used to do this providing that it has the means to execute a batch script as part of the install process (more on this in a moment). In fact, while we are building our new installer using InstallAware, we are temporarily delivering our WPF-based application and Windows Service using a WinZip self-extracting executable. The WinZip self-extractor puts the WPF application in the C:\Program Files\<application>\<version> folder, puts the Windows Service in the C:\Program Files\<application>\Common folder, and then installs and starts the Windows Service.
The trick to all of this, of course, is getting the Windows Service installed. Initially, we used the InstallUtil.exe utility to do this, but we had to err on the side of caution and deliver it with our installer because we couldn't verify whether or not we could depend on the utility being available on the target system. At some point along the way, I read this answer by #Marc Gravell. This provided the springboard to my answer here, which provides detailed instructions for having your Windows Service install itself from the command line without the need for InstallUtil.exe.
So as a set of instructions...
Update your Windows Service based on the details here.
Create a .bat file with the following commands:
cd <PathToWindowsServiceInstallationFolder>
<YourWindowsService>.exe -install
Build the installer for your WPF Service and Windows Service. Note that this should focus on deploying the files to their correct locations. You'll need to include the .bat file as part of the installer. If your installer solution allows you to copy files to a temporary folder that gets deleted at the end of the installation process, copy the .bat file to that location since you won't need it after the installer is finished.
Finally, execute the .bat file from your installer during installation. This will install the Windows Service.
It's really not that complicated all things considered.
The one thing to be aware of is that your users should plan on running the installer as an administrator. Since installing the Windows Service updates the registry, users without administrative privileges might run into problems when trying to install your product.
HTH

What is the best way of automating Windows Service deployment?

I have created a windows service using C# in Visual Studio 2010. I did a lot of research about automating the installation process. Got lots of advice but none did work for me. The windows service i have created has lots of dependencies and i would like client to have no UI interaction during the installation. I have created a setup project for this which includes all my dependencies within the installer.
Process involved:
Create a build for windows service
Push the setup file (.msi) to remote location
Call the .msi and install the service silently without user interaction.
What i did so far:
Created a powershell script to push files to remote location
Execute powershell script and install the service
Please keep in mind that powershell script
sc create "servicename" binpath="somepath"
is used for installing service from a project directory not for installing .msi file created using Setup Project these are two vast different things. If you don't understand this don't answer please.
Possible solutions:
Use (http://www.msbuildextensionpack.com/help/4.0.5.0/html/258a18b7-2cf7-330b-e6fe-8bc45db381b9.htm) msbuild extension pack.
Use buildarguments to call msbuild extension pack to install windows service.
Use (http://msdn.microsoft.com/en-us/library/x8zx72cd.aspx) Exec Task
Use WIX(Windows Installer Xml)
Now my question is. How can i push windows service installer to remote location? And how can create custom build arguments and use either msbuild extension pack or Exec Task and install the service?
I know this sounds stupid and irritating question for someone who hasn't installed the service using (.MSI) created by the Setup Project. But its my requirements which i am trying to solve since weeks in the enterprise environment.
I would do the bulk of the work from the powershell script.
Use the msbuild Exec task like you mentioned to add it to your build process. Here's a pretty good article on using the exec task to run your powershell script.
Since you are using VS 2010, a setup and deployment project is pretty easy. Add one to your solution, and add the output of your service project to it. Here's an article on adding the setup project for a windows service.
Use your powershell scripts to copy the installer .msi to the remote server. You can simply use copy-item [source] [destination] if you have access to the file share.
Stop the service on the remote machine. You can use (get-service -ComputerName [destination] -Name [service-name]).Stop() (from this question)
Install the service silently using psexec psexec \\remotecomputer "[msi-destination-path]" /qn Here's the rest of the command line options for the .msi.
Start the service using (get-service -ComputerName [destination] -Name [service-name]).Start()
I'd also add a bunch of parameters to the powershell script for destination server, service name, etc. It will make maintaining this part of your build process much easier. Your build agent will most likely have to be an administrator on the destination machine as well.
Lastly, make sure to put your powershell build script in source control!
Edit (June 2014)
VS 2013 has installer projects again! (Sorry, VS 2012)
Also, if found this awesome answer about how to install a Windows Service without using a setup project.

How to deploy windows services using MSBuild?

I have created a windows service project using Visual Studio which needs to be installed on to the remote machine using MSBuild. I have had a look at lots of resources on good ways of deploying windows services. Most answer were using PowerShell scripts which i think of as an alternative.
Can anyone provide me with good resource. Any ideas on how to deploy this. There are lots of security issues with deploying (.exe) files in enterprise environment so i am worried on picking any alternatives.
I will really appreciate any suggestions.
you can use MSBuild
example for install:
<MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Install" ServiceName="SomeWindowsService" User="UserLocal" Password="PassLocal" ServicePath="\\RemoteComp2\PathForYourService\WindowsService.exe" RemoteUser="UserRemoteComp2" RemoteUserPassword="PassRemoteComp2" MachineName="RemoteComp2"/>
for more information look follow link http://www.msbuildextensionpack.com/help/4.0.5.0/html/258a18b7-2cf7-330b-e6fe-8bc45db381b9.htm
You can use Exec Task (http://msdn.microsoft.com/en-us/library/x8zx72cd.aspx) look at the link.
Using powershell remoting would be another option for sure.
To install service to the remote machine you can try ServiceController task that can control a Windows service. From here.
Have a look at PSExec (http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx) depending on your requirements and deployment scenario. It, combined with the MSBuild Exec task, would allow you to install the service remotely.

How to update windows service (Not auto update)

I inherited a couple c# windows service projects. I have fixed some bugs in the code and now I need to deploy the new executable. What is the normal process for updating / replacing a windows service? I have remote desktop access to the server that I am installing it on.
Just stop the service and replace the executable and possibli the additional dependency you have updated. Of course it could be helpful have a backup of the running service, just to be safe :)
If you need to know exactly where the service is running, open Service Control Manager, select your serice, and look in the properties/general: you will find the executable path.
It's enough to replace exe and dlls. Obviously you have to stop the service first. If dlls were registered in GAC they might be used by other software on that machine, in such case before compiling and deploying change their version.
For a .Net Windows Service you need to use the InstallUtil command line tool to uninstall the old service, then use it to install the new one.
See...
http://msdn.microsoft.com/en-us/library/50614e95(v=vs.80).aspx

Visual Studio: Publish application

I made a simple Windows application to test how I can publish my application.
So what I want to know is how can I publish my application so that it creates an installer so that other users around the world can download, install and use my application?
Thanks
You could use the "setup" project available in visual studio, that creates a MSI file.
Also you may use the publish concept called "click-once-deployment".
Please go through this article that explains the methodology:
http://www.codeproject.com/KB/install/ClickOnce-Deployment.aspx
Create homepage to describe your application information, update somewhere for others to download. Well, you can give a try by creating a site on CodePlex, SourceForge...
You could try ClickOnce.
ClickOnce deployment allows you to publish Windows-based applications to a Web server or network file share for simplified installation.
You just need to define which prerequisites you want to include in bootstraper, as described here

Categories