Question

Je suis nouveau à Msbuild et j'essaie actuellement de créer un script Msbuild qui déploiera mon service Windows C # au serveur de test à distance.

Je pense à utiliser l'utilitaire SC.EXE à cette fin.Lire à ce sujet Je n'ai trouvé aucun moyen de vérifier si le service Windows est installé sur un serveur distant.Si le service est installé, j'ai besoin de l'arrêter et de mettre à jour les fichiers nécessaires, sinon j'ai besoin d'enregistrer le service.

P.s.Pour les constructions de libération, je prévois d'utiliser WIX pour créer un package MSI.

Était-ce utile?

La solution

You need MSBuild Comminity Tasks. In latest build exists an example in MSBuild.Community.Tasks.v1.2.0.306\Source\Services.proj. It will solve first part of your question:

<PropertyGroup>
    <MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\MSBuild.Community.Tasks\bin\Debug</MSBuildCommunityTasksPath>
</PropertyGroup>

<Import Project="$(MSBuildProjectDirectory)\MSBuild.Community.Tasks\MSBuild.Community.Tasks.Targets"/>

<Target Name="Test">
    <CallTarget Targets="DoesServiceExist" />
    <CallTarget Targets="GetServiceStatus" />
    <CallTarget Targets="ServiceControllerStuff" />
</Target>

<Target Name="DoesServiceExist">
    <ServiceQuery ServiceName="MSSQLServer123" MachineName="127.0.0.1" >
        <Output TaskParameter="Exists" PropertyName="Exists" />
        <Output TaskParameter="Status" PropertyName="ServiceStatus" />
    </ServiceQuery>
    <Message Text="MSSQLServer Service Exists: $(Exists) - Status: $(ServiceStatus)"/>
</Target>

<Target Name="GetServiceStatus">
    <ServiceQuery ServiceName="MSSQLServer" MachineName="127.0.0.1">
        <Output TaskParameter="Status" PropertyName="ResultStatus" />
    </ServiceQuery>
    <Message Text="MSSQLServer Service Status: $(ResultStatus)"/>
</Target>

<Target Name="ServiceControllerStuff">
    <ServiceController ServiceName="aspnet_state" MachineName="127.0.0.1" Action="Start" />
    <ServiceController ServiceName="aspnet_state" MachineName="127.0.0.1" Action="Stop" />
</Target>

Those MSBuild task is just a wrapper around .Net class ServiceController. Take a look for documentation to understand how it works and how you can configure it in details.

Second part includes installing service. For that purpose sc.exe suits very well.

Autres conseils

A complete solution is posted here. May help future visitors.

Update: Link updated as the other blogging service went down.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top