Deployment MSBuild。检查是否安装了windows服务

Deployment MSBuild。检查是否安装了windows服务,deployment,msbuild,windows-services,remote-server,Deployment,Msbuild,Windows Services,Remote Server,我是msbuild新手,目前正在尝试创建msbuild脚本,该脚本将把我的C#windows服务部署到远程测试服务器 我正在考虑为此使用sc.exe实用程序。读到这篇文章,我没有找到一种方法来检查远程服务器上是否安装了windows服务。如果安装了服务,那么我需要停止它并更新必要的文件,否则我需要注册该服务 另外,对于发布版本,我计划使用WiX创建MSI包。您需要。 在最新版本中,MSBuild.Community.Tasks.v1.2.0.306\Source\Services.proj中存在

我是msbuild新手,目前正在尝试创建msbuild脚本,该脚本将把我的C#windows服务部署到远程测试服务器

我正在考虑为此使用sc.exe实用程序。读到这篇文章,我没有找到一种方法来检查远程服务器上是否安装了windows服务。如果安装了服务,那么我需要停止它并更新必要的文件,否则我需要注册该服务

另外,对于发布版本,我计划使用WiX创建MSI包。

您需要。 在最新版本中,MSBuild.Community.Tasks.v1.2.0.306\Source\Services.proj中存在一个示例。 它将解决您问题的第一部分:


$(MSBuildProjectDirectory)\MSBuild.Community.Tasks\bin\Debug

这些MSBuild任务只是.Net类的包装器。查看文档,了解它是如何工作的,以及如何详细配置它


第二部分包括安装服务。为了这个目的,我需要一套合适的衣服

发布了完整的解决方案。可能对未来的游客有所帮助


更新:链接在其他博客服务关闭时更新。

谢谢。我有个问题。服务查询是否只能检查远程计算机或本地服务上的服务状态?我已更新了默认脚本,并定义了支持的参数MachineName=“127.0.0.1”以连接到服务器。@Philter:谢谢您指出。我切换到更干净的URL,因此您不再需要最后的.html扩展名。现在更新链接。
<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>