Search code examples
powershellmsdeploy

How do I define setParamFile using the MSDeploy API


How do I define the -setParamFile parameter from MSDeploy.exe using the MSDeploy API?

I'm trying to write the equivalent of the following in powerShell:

msdeploy -verb:sync -source:package="c:\MyZip.zip" -dest:auto -setParamFile="c:\StagingParameters.xml"

Here's what I have so far:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Deployment")
$destBaseOptions   = new-object Microsoft.Web.Deployment.DeploymentBaseOptions
$syncOptions       = new-object Microsoft.Web.Deployment.DeploymentSyncOptions
$deploymentObject = [Microsoft.Web.Deployment.DeploymentManager]::CreateObject("package","C:\MyZip.zip")

#TODO -setParamFile="c:\StagingParameters.xml"

$deploymentObject.SyncTo("auto","",$destBaseOptions,$syncOptions);

Solution

  • Gotta love reflector!

    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Deployment")
    $destBaseOptions   = new-object Microsoft.Web.Deployment.DeploymentBaseOptions
    $syncOptions       = new-object Microsoft.Web.Deployment.DeploymentSyncOptions
    $deploymentObject = [Microsoft.Web.Deployment.DeploymentManager]::CreateObject("package","C:\MyZip.zip")
    
    #-setParamFile
    $deploymentObject.SyncParameters.Load("c:\StagingParameters.xml");
    
    $deploymentObject.SyncTo("auto","",$destBaseOptions,$syncOptions);