user137348
user137348

Reputation: 10332

Stop/Run windows service and building a solution

I'd like to have a script that stops a certain windows service,build or rebuild a solution and runs the service after the build process finished.

Should I use Msbuild for this ? Or is there any other way ?

Upvotes: 1

Views: 637

Answers (4)

ikutsin
ikutsin

Reputation: 1138

MS build part:

<PropertyGroup>
  <ServiceName>Service</ServiceName>
</PropertyGroup>
<Target Name="PostBuild">
  <Exec Command="net stop $(ServiceName)" ContinueOnError="true" Condition="$(ServiceName)!=''" />
  [. rest of the logic here .]
  <Exec Command="net start $(ServiceName)" ContinueOnError="true" Condition="$(ServiceName)!=''" />
</Target>

Upvotes: 0

Oded
Oded

Reputation: 499002

You can use a batch file that will stop the service, build the solution then start the service:

net stop "service name"
<path to msbuild>\msbuild.exe <path to solution file>
net start "service name"

See how to start/stop services from the command line, and the msbuild command line reference.

Your other option, as mentioned is to use the MSBuild community tasks. There are many of them - ServiceController is the specific one for your need.

Upvotes: 3

Black Frog
Black Frog

Reputation: 11713

Is the service you are stopping the same executable you are building in the solution? If so, why not do dynamic code in the service?

Upvotes: 1

Alex
Alex

Reputation: 13229

MSBuild is your answer. Controlling the services can be accomplished easily by using the Community Tasks, specifically the service controller task.

http://msbuildtasks.tigris.org/

Upvotes: 7

Related Questions