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.
Related
We have a solution which consists of several projects. Some of the projects are windows tasks, some are windows services and some are mvc-websites which are running on a remote server. On this server we are currently implementing TeamCity as CI server for automating our builds and deployments. As of now, the projects are deployed on this same server. The build, test steps etc works fine but I am not sure how to deploy the tasks and services. All tutorials about this subject (at least those I have seen) only concerns deployment of websites.
The most obvious way is to have a post-build step running a powershell script which are uninstalling the current running windows service, removes the old service, copy the new dll and start the service again. The windows task files could simply be replaced directly with the new version.
However, I do not like this solution, it feels very blunt and could perhaps be hard to implement if the deployment server is remote.
Does anyone have any better suggestion on how to make the deployment?
Have a nice day!
Try to look at Octopus depoy: http://octopusdeploy.com/. You can easy integrate it with TeamCity. It has abillity to star/stop service and much more. Moreover it use nuget packages.
You can deploy windows services via Web Deployment Tool as well. All you have to do is to create manifest.xml file with runCommand (un/install and start/stop service) and dirPath (deploy service) providers.
My manifest file which deploys also DB and web site looks like:
<sitemanifest>
<dbDacFx path='$dbSource' />
<runCommand path='$presync' waitInterval='30000'/>
<dirPath path='$winSource' />
<runCommand path='$postsync' waitInterval='30000'/>
<IisApp path='$webSource' managedRuntimeVersion='v4.0'/>
<setAcl path='$webSource' setAclResourceType='Directory'/>
<setAcl path='$webSource' setAclResourceType='Directory' setAclUser='anonymousAuthenticationUser'/>
</sitemanifest>
It's generated by build script in Psake, but you can do it as you wish.
I wrote two blogs about this topic, but they are in czech language.
Everything in one package
Parametrization of package
Hope, there is something that can help you.
Inedo's BuildMaster can pick up right where TeamCity leaves off using the BuildMaster TeamCity Extension. There's a free version avaiable that will probably solve your requirements.
We have to solve this own problem when we use BuildMaster to build/deploy BuildMaster (before installers get built), and if you take a look at the BuildMaster Specifics (Inedo.com > Support > Specifics > BuildMaster, you can see precicely how we stop/deploy/start the Windows service.
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.
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
How do I remotely install a Windows service using C#?
(I prefer not calling sc.exe / psexec / powershell remoting).
Thanks!
Yuval
You should take a look at the TopShelf project. They make deployment of windows services pretty painless. XCopy and invoke with any of these command line options and you should be good to go.
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.