cevap

5

Bunun için genellikle düz powershell veya msbuild kullanıyorum. Pullu msdeploy'dan kaçınmaya çalışıyorum. Bekleme aralık değil

<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

msdeploy ile çok fazla deneyim yaşamadan (bunu birkaç kez kullandı ancak nasıl çalıştığını asla anlayamadı) kaputun altında "), ben de bir tür lapa lapa olduğunu hissediyorum itiraf etmeliyim. Ancak bu sadece fikirlerdir, ancak msbuild'i copy-commands ve bir çift yarasa dosyası ile bitirdim. Çözümünüz daha sağlam görünüyor, ancak kendinizin bir çeşit dosya erişimi olduğunu söylediğiniz gibi. Bizim durumumuzda biz yaptık! Yani bu çözüm işe yarıyor ve ben bir cevap olarak işaretleyeceğim. "Kaldırma servisi" mi yoksa "durdurma servisi" hizmetin incelikle durması için ne kadar bekleyeceğini biliyor musunuz? Sonsuza dek? – marko

+1

Merhaba Marko, çevrimiçi dokümanlardan http://www.msbuildextensionpack.com/help/4.0.8.0/index.html, retryattempts özelliğinin 60 olarak varsayılan olduğunu söylüyor. –

1

Böyle tanımlanan msdeploy paketini kullanıyor: presync.cmd

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

: postsync.cmd

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

:

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

tüm dosyalar powershell komut dosyası tarafından oluşturulur.

+0

ne olur: Eğer böylece hedef hedefe dosya kopyalayabilirsiniz varsayarak böylece çok kullanışlı Msbuild uzatma takımını kullanabilirsiniz msbuild olarak bu işlemi yapacaktır (Robocopy bunun için kullanışlıdır) yeterince büyük mü? – marko

+0

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

İlgili konular