Reputation: 10332
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
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
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
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
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