msdeploy DeploymentProviderOptions上的waitInterval配置

时间:2015-03-04 11:52:10

标签: msdeploy

作为构建和部署代码的一部分,我们遇到与停止和启动服务相关的超时问题。

以下是停止服务的代码

public DeploymentChangeSummary StopService(WebPublisherParameters parameters)
    {
        var sourceOptions = new DeploymentBaseOptions();

        var destinationEndpointOptions = new DeploymentBaseOptions()
        {
            ComputerName = parameters.DestinationComputer
        };
        var destProviderOptions = new DeploymentProviderOptions(DeploymentWellKnownProvider.RunCommand)
        {                
            Path = "Net Stop " + parameters.DestinationName
        };

        using (var sourceObj =
            DeploymentManager.CreateObject(new DeploymentProviderOptions(DeploymentWellKnownProvider.RunCommand), sourceOptions))
        {
            return sourceObj.SyncTo(destProviderOptions, destinationEndpointOptions, new DeploymentSyncOptions());
        }
    }

我们遇到了超时问题,并且因为服务没有及时停止而导致构建失败。

我们尝试像这样配置waitInterval

destProviderOptions.ProviderSettings["waitInterval"] = 20000;

但意识到它是一个只读配置,所以我想知道是否有人能指出我们正确的方向以编程方式执行此操作而不是使用命令行选项。

由于 Tapashya

1 个答案:

答案 0 :(得分:0)

您需要设置DeploymentBaseOptions对象的RetryInterval。编辑了问题的代码。

public DeploymentChangeSummary StopService(WebPublisherParameters parameters)
{
    var sourceOptions = new DeploymentBaseOptions();

    var destinationEndpointOptions = new DeploymentBaseOptions()
    {
        ComputerName = parameters.DestinationComputer
    };
    var destProviderOptions = new DeploymentProviderOptions(DeploymentWellKnownProvider.RunCommand)
    {                
        Path = "Net Stop " + parameters.DestinationName
    };

    using (var sourceObj =
        DeploymentManager.CreateObject(new DeploymentProviderOptions(DeploymentWellKnownProvider.RunCommand), sourceOptions))
    {
        destinationEndpointOptions.RetryInterval = 2 * 1000; // Set wait interval to 2 minutes
        return sourceObj.SyncTo(destProviderOptions, destinationEndpointOptions, new DeploymentSyncOptions());
    }
}