2010-11-13 41 views
4

如何使用MSDeploy API從MSDeploy.exe定義-setParamFile參數?如何使用MSDeploy API定義setParamFile

我試着寫在PowerShell中下面的等價:

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

這是我到目前爲止有:

[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); 

回答

8

愛是愛反射!

[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); 
+0

您應該將其標記爲答案。 ;) – JasonMArcher 2010-11-14 20:11:47