« Visual Studio Build Events using PowerShell | Main | Firefox & IE Tab: Rendering the Intranet in IE »

Remote Service Deployment with VS.NET PowerShell Build Events

This post is a follow up to "Visual Studio Build Events using PowerShell". I wanted to post a more compelling example of what could be done easily with the Pre/Post Build events in Visual Studio .NET using PowerShell.

When developing Windows Services that are deployed on a remote machine within your development environment it can be very annoying to have to stop and start the service each time you build. The following script when executed within a post build event (read the original article) on a Windows Service project will take the following steps:

  1. Stop the service on the remote computer
  2. Wait for the service to stop and remove the files in the remote service root directory (to ensure a fresh deployment each time)
  3. Copy all the files from the Visual Studio project's Target Directory to the remote service root directory
  4. Start the service on the remote computer

DeployConfig.xml Fragment

<project targetFileName="Service.exe">

   <buildConfig name="Debug">

      <user name="default">

         <buildEvent name="Post">

            <![CDATA[write-Output "Script Started"

write-Output ""

write-Output "Stopping IMM DAM Service on REMOTEMACHINENAME"

write-Output ""

$remoteService = (Get-WmiObject -computer REMOTEMACHINENAME Win32_Service -Filter "Name='Service Title'")

$hideOutput = ($remoteService.StopService() | out-string)

 

write-host -no "Waiting for 'Service Title' to stop"

while((Test-Path '\\REMOTEMACHINENAME\c$\SERVICEDIR\*.*') -eq $True) {

   remove-item -path "\\REMOTEMACHINENAME\c$\SERVICEDIR\*.*" -force -erroraction silentlycontinue

   write-host -no "."

}

write-Output ""

write-Output ""

 

copy-item -path "{targetDir}*.*" -destination "\\REMOTEMACHINENAME\c$\SERVICEDIR" -force

write-Output "Files Copied"

write-Output ""

 

write-Output "Starting 'Service Title' on REMOTEMACHINENAME"

write-Output ""

$hideOutput = ($remoteService.StartService() | out-string)

write-Output "Script Complete"]]>

         </buildEvent>

      </user>

   </buildConfig>

</project>

TrackBack

TrackBack URL for this entry:
http://www.capdes.com/mt/mt-tb.cgi/14

Listed below are links to weblogs that reference Remote Service Deployment with VS.NET PowerShell Build Events:

» levitra drugs from cailis
Hope this information helps, I would be happy to answer questions via the site forums.. [Read More]

» Search engines 'address' teachers' plagiarism from internet college course
ATL general secretary, Dr Mary Bousted, said: "Unsurprisingly pupils are using all the means available to push up their [Read More]

» Andy McKenna On Republicans In from hot ticket chicago
Police Show Up At Woman's Home, Give Her Ticket A woman is ticketed after she ... Bush On Iraq [Read More]

» CHS open house spotlights industrial from nike triax c3 heart rate monitor
The business is employing two CHS graduates. n Camaco for job shadowing and donating metal for the high school [Read More]

» PC Virtualization Provider Innotek Snapped from nt operating system window
PC Virtualization Provider Innotek Snapped Up by SunIT Jungle, NY -22 hours agoVirtualBox allows desktop and laptop machines to support guest operating [Read More]

About

View Eric Schoonover's profile on LinkedIn
 

Follow me on Twitter
 
© Copyright 2007, Eric Schoonover

Search

Post Info

This page contains a single entry from the blog posted on March 8, 2007 2:30 AM.

The previous post in this blog was Visual Studio Build Events using PowerShell.

The next post in this blog is Firefox & IE Tab: Rendering the Intranet in IE.

Many more can be found on the main index page or by looking through the archives.

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.