【发布时间】:2012-12-19 11:08:35
【问题描述】:
好的,这就是我想做的——
我们有一个 Windows 服务,我们希望在每次成功的 CI 构建之后自动将该服务部署到测试环境 - 为此我们想到了以下方法 -
- 构建 Windows 服务项目(连同依赖项)
- 停止windows服务
- 将项目输出从输出文件夹复制到 Windows 服务文件路径
- 启动服务
但是,目前我在启动和停止 Windows 服务方面遇到了问题。
这是 MSBuild sn-p -
<!-- TODO: do this using Powershell instead of normal commandline so that it can be executed on remote machines as well -->
<Exec Command="Net Stop CreditProcessing" />
<!-- Exec Command="$(PowerShellExe) -NoProfile -Noninteractive -command "&{ Stop-Service CreditProcessing }"" /-->
<!-- TODO: The destination needs to come from the env variable or rsp file? -->
<Copy
SourceFiles="@(WindowsServiceFilesToDeploy)"
DestinationFiles="@(WindowsServiceFilesToDeploy->'D:\WindowsServices\Credit Processing Service%(RecursiveDir)%(Filename)%(Extension)')" />
<Exec Command="Net Start CreditProcessing" />
<!--Exec Command="$(PowerShellExe) -NoProfile -Noninteractive -command Start-Service CreditProcessing" /-->
我尝试使用直接命令行命令和 powershell 命令。
A) 这是我尝试使用普通命令运行此构建时遇到的问题 - 服务需要一些时间来启动/停止,并且构建没有等待足够长的时间并报告错误并停止
“...服务无法启动”。 "服务没有报错"
或有时在停止时
“当前状态下无法控制服务。”
而如果我们立即检查服务,它将处于“启动”阶段,很快就会进入“启动”阶段。有什么方法可以让构建更有耐心吗?如果直接从命令提示符运行,该命令不会执行此操作。
B)如果我使用上面的powershell命令(目前在sn-p中注释),这是我们面临的问题 -
它只是在构建日志中打开 powershell 提示符,然后什么都不做
您能否帮助避免这些问题(至少其中之一)?我认为如果它工作正常,更推荐使用 powershell 路线,但我愿意接受建议。
还有几个问题 -
我们想在远程机器上部署服务(并因此停止并重新启动)(而不是发生此 CI 构建的地方) - 无论如何都可以这样做?
有没有办法添加一个检查服务是否已经在运行并且只有在它运行时才停止?如果它停止了,我们再次尝试停止,它会给出“服务未启动”错误
【问题讨论】:
-
你能发布你是如何定义 $(PowerShell) 的吗?查看屏幕截图,似乎它在 powershell.exe 的路径之后注入了一个换行符。这可以解释您所看到的行为。
-
是的!就是这样!! @JohnL 你能把这个作为答案,这样我就可以投票和标记它吗?!!
标签: powershell msbuild windows-services continuous-integration