risposta

5

Io di solito uso direttamente powershell o msbuild per questo. Cerco di evitare il msdeploy traballante. In msbuild è possibile utilizzare il pacchetto estensione msbuild molto utile in tal modo, in modo da supponendo che si può copiare i file al vostro target di destinazione (Robocopy è a portata di mano per questo) questo farà il resto:

<Project ToolsVersion="4.0" DefaultTargets="InstallService" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <UsingTask AssemblyFile="..\packages\MSBuild.Extension.Pack.1.2.0\lib\net40\MSBuild.ExtensionPack.dll" 
TaskName="MSBuild.ExtensionPack.Computer.WindowsService"/> 

    <PropertyGroup> 
    <MachineName Condition="$(MachineName)==''"></MachineName> 
    <ServiceName Condition="$(ServiceName)==''"></ServiceName> 
    <ServicePath Condition="$(ServicePath)==''"></ServicePath> 
    <User Condition="$(User)==''"></User> 
    <Password Condition="$(Password)==''"></Password> 
    <SuppressStart Condition="$(SuppressStart)==''"></SuppressStart> 
    </PropertyGroup> 

    <Target Name="CheckProperties" BeforeTargets="StopService"> 
    <Message Text="MachineName: $(MachineName)"/> 
    <Message Text="ServiceName: $(ServiceName)"/> 
    <Message Text="ServicePath: $(ServicePath)"/> 
    <Message Text="User : $(User)"/> 
    <Message Text="SuppressStart : $(SuppressStart)"/> 
    </Target> 

    <Target Name="StopService" BeforeTargets="InstallService"> 

    <MSBuild.ExtensionPack.Computer.WindowsService 
     TaskAction="CheckExists" 
     ServiceName="$(ServiceName)" 
     MachineName="$(MachineName)"> 
     <Output TaskParameter="Exists" PropertyName="DoesExist"/> 
    </MSBuild.ExtensionPack.Computer.WindowsService> 

    <MSBuild.ExtensionPack.Computer.WindowsService 
     TaskAction="Stop" 
     ServiceName="$(ServiceName)" 
     MachineName="$(MachineName)" 
     Condition="$(DoesExist)=='True'"> 
    </MSBuild.ExtensionPack.Computer.WindowsService> 
    </Target> 

    <Target Name="StartService" AfterTargets="InstallService"> 

    <MSBuild.ExtensionPack.Computer.WindowsService 
    TaskAction="CheckExists" 
    ServiceName="$(ServiceName)" 
    MachineName="$(MachineName)"> 
     <Output TaskParameter="Exists" PropertyName="DoesExist"/> 

    </MSBuild.ExtensionPack.Computer.WindowsService> 

    <MSBuild.ExtensionPack.Computer.WindowsService 
     TaskAction="Start" 
     ServiceName="$(ServiceName)" 
     MachineName="$(MachineName)" 
     Condition="$(DoesExist)=='True' And $(SuppressStart)=='False'" 
     RetryAttempts="20"> 
    </MSBuild.ExtensionPack.Computer.WindowsService> 
    <Message Text="Service $(ServiceName) set not to start" Condition="$(SuppressStart)=='True'" Importance="High" /> 
    </Target> 

    <Target Name="InstallService"> 

    <PropertyGroup> 
     <ServiceExeExists Condition="Exists('$(ServicePath)')">True</ServiceExeExists> 
    </PropertyGroup> 

    <Message Text="Installing $(ServicePath) %(ServiceName.Identity)" Importance="high"/> 
    <MSBuild.ExtensionPack.Computer.WindowsService 
     TaskAction="CheckExists" 
     ServiceName="$(ServiceName)" 
     MachineName="$(MachineName)"> 
     <Output TaskParameter="Exists" PropertyName="DoesExist"/> 

    </MSBuild.ExtensionPack.Computer.WindowsService> 

    <Message Text="Installed $(ServiceName) $(ServicePath) for $(User) and $(Password)" Importance="high"/> 
    <MSBuild.ExtensionPack.Computer.WindowsService 
     TaskAction="Install" 
     ServiceName="$(ServiceName)" 
     User="$(User)" 
     Password="$(Password)" 
     ServicePath="$(ServicePath)" 
     MachineName="$(MachineName)" 
     Condition="!$(DoesExist)"/> 

    <MSBuild.ExtensionPack.Computer.WindowsService 
     TaskAction="SetAutomatic" 
     ServiceName="$(ServiceName)" 
     MachineName="$(MachineName)" 
     Condition="!$(DoesExist)"/> 
    <Warning Text="%(ServiceName.Identity) service already exists" Condition="$(DoesExist)"/> 

    </Target> 

</Project> 
+0

Senza avere troppa esperienza con msdeploy (lo ha usato un paio di volte ma non ha mai veramente capito come funziona " sotto i cappucci "), devo ammettere che anch'io sento che è un po 'traballante. Sono solo opinioni, ma alla fine ho usato msbuild con i comandi di copia e un paio di file bat. La tua soluzione sembra più robusta, ma ha bisogno di te quando dici una qualche forma di accesso ai file. Nel nostro caso l'abbiamo fatto! Quindi questa soluzione funziona e la contrassegnerò come una risposta. Sapete per quanto tempo "servizio di disinstallazione" o "servizio di arresto" attenderà che il servizio si arresti con garbo? Per sempre? – marko

+1

Ciao Marko felice di poterti aiutare, dai documenti online http://www.msbuildextensionpack.com/help/4.0.8.0/index.html si dice che la proprietà retryattempts è impostata su 60. –

1

Stiamo usando il pacchetto msdeploy definita in questo modo:

<sitemanifest> 
    <runCommand path='presync.cmd' waitInterval='30000'/> 
    <dirPath path='$winSvc' /> 
    <runCommand path='postsync.cmd' waitInterval='30000'/> 
</sitemanifest> 

il presync.cmd:

net stop Svc 
installUtil /u /name=Svc $destPath\Svc.exe 

il postsync.cmd:

installUtil /name=Svc $destPath\Svc.exe 
net start Svc 

Tutti i file sono generati dallo script PowerShell.

+0

cosa succede se l'intervallo di attesa non è abbastanza bene? – marko

+0

http://technet.microsoft.com/en-us/library/ee619740(v=ws.10).aspx –