Skip to content

Instantly share code, notes, and snippets.

@mjul
Created March 22, 2012 17:04
Show Gist options
  • Save mjul/2159742 to your computer and use it in GitHub Desktop.
Save mjul/2159742 to your computer and use it in GitHub Desktop.
MSBuild start and stop WCF service host
<PropertyGroup>
<WcfSvcHost>$(MSBuildProjectDirectory)\Build\WcfServiceHost\wcfsvchost.exe</WcfSvcHost>
<AsyncStartWcfServiceHostCode>
<![CDATA[
Public Shared Function ScriptMain() as String
Dim p As New Process
Dim pi As New ProcessStartInfo
pi.arguments = "/service:App\MyApp.Server.Services\bin\Debug\MyApp.Server.Services.dll /config:App\MyApp.Server.Services\bin\Debug\MyApp.Server.Services.dll.config"
pi.FileName = "$(WcfSvcHost)"
p.startinfo = pi
p.Start()
return p.Id.ToString()
End Function
]]>
</AsyncStartWcfServiceHostCode>
</PropertyGroup>
<Target Name="StartServices">
<Message Text="Starter WCF services...." />
<Script Language="VB" Code="$(AsyncStartWcfServiceHostCode)" Imports="System;System.Diagnostics">
<Output TaskParameter="ReturnValue" PropertyName="WcfServiceHostProcessId" />
</Script>
<Message Text="WCF PID: $(WcfServiceHostProcessId)" />
</Target>
<Target Name="StopServices">
<Message Text="Stopper WCF services...." />
<Exec Command="taskkill /F /PID $(WcfServiceHostProcessId) /T" />
</Target>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment