msdeploy DeploymentProviderOptions 上的 waitInterval 配置

waitInterval configuration on msdeploy DeploymentProviderOptions

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

这是停止服务的代码

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;

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

谢谢 塔帕夏

您需要设置 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());
    }
}