答えて

5

私は通常、これには直筆またはmsbuildを使用します。私は薄れたmsdeployを避けようとします。

<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の経験があまりありません(数回使用しましたが、実際の動作を決して理解できませんでした)私はあまりにも薄すぎると感じていることを認めなければなりません。しかしそれはちょっとした意見ですが、私はコピーコマンドといくつかのバットファイルを使ってmsbuildを使い終えました。あなたのソリューションはより堅牢なようですが、何らかの種類のファイル共有アクセスといっても必要です。 私たちの場合、私たちはしました!このソリューションは動作します&私は答えとしてマークします。 "アンインストールサービス"または "サービス停止"がサービスが正常に停止するのをどれくらい待つか知っていますか?永遠に? – marko

+1

こんにちはMarkoさん、こんにちは、オンライン文書http://www.msbuildextensionpack.com/help/4.0.8.0/index.htmlから、retryattemptsプロパティのデフォルト値は60になりました。 –

1

私たちは、このように定義された場合msdeployパッケージを使用している: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 

すべてのファイルは、PowerShellスクリプトによって生成されます。

+0

待機間隔がない場合は何: MSBuildのでは、そう、これは残りを行います(Robocopyのは、そのために便利です)、あなたのターゲットの宛先にファイルをコピーすることができますと仮定し、これは非常に便利なMSBuildの拡張パックを使用することができます十分に素晴らしい? – marko

+0

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

関連する問題