MSDeploy任务和预同步

时间:2012-06-05 19:00:20

标签: msbuild msdeploy web-deployment msbuild-task

是否可以通过MSDeploy任务指定preSync / postSync命令?如果没有,我该如何做到这一点?

1 个答案:

答案 0 :(得分:1)

您使用的是哪种MSDeploy任务?如果它是通过msdeploy.exe的Exec然后是,当然,如果它是某种不直接支持它们的包装器,那么你可以通过再次使用run-command provider调用sync来模拟它们,因为pre / post-sync只是另一个调用同步在try / catch / finally结构中包装主同步。

private int ExecuteWorker()
{
    ...
    if (!this.HandleAuxillarySync("-preSync", this._commandLine._preSyncParameters, retbaseOptions2))
        return -1;
    DeploymentChangeSummary deploymentChangeSummary;
    try
    {
        deploymentChangeSummary = @object.SyncTo(retproviderOptions2, retbaseOptions2, syncOptions);
    }
    ...
    finally
    {
        this.HandleAuxillarySync("-postSync", this._commandLine._postSyncParameters, retbaseOptions2);
    }
    this.HandleAuxillarySync("-postSyncOnSuccess", this._commandLine._postSyncOnSuccessParameters, retbaseOptions2);
    ...

private bool HandleAuxillarySync(string syncType, Dictionary<string, string> sourceParameters, DeploymentBaseOptions destBaseOptions)
{
    ...
    try
    {
        using (DeploymentObject @object = DeploymentManager.CreateObject(retproviderOptions, retbaseOptions))
        @object.SyncTo(destBaseOptions, syncOptions);
            flag = true;
    }