How to set destination website on MSDeploy.exe com

2020-06-10 15:29发布

问题:

I have a Web Deploy 3.5 package that I want to deploy to a remote server. How do I specify the name of the site on the MSDeploy.exe command line?

Here's what I have so far:

C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe
    -source:package='package.zip' 
    -dest:auto,computerName="ServerName",includeAcls="False" 
    -verb:sync 
    -disableLink:AppPoolExtension 
    -disableLink:ContentExtension 
    -disableLink:CertificateExtension 
    -setParamFile:"package.SetParameters.xml"

But the name of the site is specified in the package.SetParamters.xml file, and I'd prefer to set it on the command line. Some of the places I want to deploy this package are different sites located on the same server, like our Stage and UAT sites.

I've looked at using the iisApp and appHostConfig providers described here: http://technet.microsoft.com/en-us/library/dd569040%28v=ws.10%29.aspx

But I'm having trouble using those in combination with a package file.

回答1:

You can override it using setParam:

msdeploy.exe
    -source:package='package.zip' 
    -dest:auto,computerName="ServerName",includeAcls="False" 
    -verb:sync 
    -disableLink:AppPoolExtension 
    -disableLink:ContentExtension 
    -disableLink:CertificateExtension 
    -setParamFile:"package.SetParameters.xml"
    -setParam:name="IIS Web Application Name",value="site name"


回答2:

To do the same in Powershell (see Richard Szalay's answer), you have to be a little careful about the command line argument handling - especially where spaces are involved. I find that it is best to pass them as an array where the desired command line arguments are effectively split on the space character. Note that the lines below are comma separated and also that the parameter name 'IIS Web Application' is split. I left that one on one line for improved readability.

$msdeploy = "C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe";

$msdeployArguments = 
    '-source:package="package.zip"',
    '-dest:auto,computerName="<ServerName>",includeAcls="False"',
    '-verb:sync',
    '-disableLink:AppPoolExtension',
    '-disableLink:ContentExtension',
    '-disableLink:CertificateExtension',
    '-setParam:name="IIS', 'Web', 'Application', 'Name",value="<WebsiteName>"'

& $msdeploy $msdeployArguments

Update

I had problems when I went back to parametrize the website Name. Because I had used single quotes for the strings, I chose to use concatenation rather than string interpolation. Unfortunately, the commas that delimited the elements in the array seem to have been evaluated prior to the concatenation. The result was that instead of concatenating strings within an array element, I was concatenating new elements to the array. My solution was to use parentheses to surround the array element and force the concatenation to be performed first.

$msdeployArguments = 
    '-source:package="package.zip"',
    ('-dest:auto,computerName="' + $webServerName + '",includeAcls="True"'),
    '-verb:sync',
    '-disableLink:AppPoolExtension',
    '-disableLink:ContentExtension',
    '-disableLink:CertificateExtension',
    '-setParam:name="IIS', 'Web', 'Application', ('Name",value="' + $websiteName + '"');


回答3:

I have tried out all of the answers from here (and basically all answers from the internet) none of them was working for me. Not sure why. Then I found this page which explains how to use MSDeploy for BackUps (I just reversed it to use for deploy). The secret souse is "contentPath". Which is a bit misleading because in this case not a path on the Disk (however I have seen examples which was using it to pass in the hosted Site Physical path). But I didn't wanted to use the Physical path. And you don't have to! The trick is: it can contain the WebSite or child site (in IIS yoursite.com/shop, so I guess it is a path in IIS) name.

Usage for backup:

msdeploy –verb:sync -source:contentPath="yoursite.com" -dest:package=c:\Backups\yoursite.zip

Usage to deploy:

msdeploy –verb:sync -source:package=c:\Deployment\yoursite.zip -dest:contentPath="yoursite.com"

I was wasting almost a day with declareParam, setParam, etc... However it is so simple!

Hope it helps...