title: MsDeploy - Can't update Application Pool
body: <p>I've been browsing dozens of sites to help me deploy a web service to an IIS using MsDeploy.
  I need to create the application, modify application pool and enable protocols, and update a appSetting (that contains a connection string, don't ask me why).</p>
  
  <p>I can do all of these, except applying the good Application pool.</p>
  
  <p>Here's the parameters.xml file I added to the project :</p>
  
  <pre><code>&lt;parameters&gt;
    &lt;parameter tags="IisApp" defaultValue="Default Web Site/MyWebService" name="IIS Web Application Name"&gt;
      &lt;parameterEntry match="@defaultValue" scope="IisApp" kind="ProviderPath"/&gt;
      &lt;parameterEntry match="@defaultValue" scope="setAcl" kind="ProviderPath"/&gt;
    &lt;/parameter&gt;
    &lt;parameter name="Configuration Connection String" defaultValue="Some real Connection String in there" tags=""&gt;
      &lt;parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add[@key='ConfigurationSQLConnectionString']/@value" /&gt;
    &lt;/parameter&gt;
    &lt;parameter name="Application Pool" defaultValue="MyOwnAppPool" description="Application pool for this site"&gt;
      &lt;parameterEntry kind="DeploymentObjectAttribute" scope="application" match="/application/@applicationPool" /&gt;
    &lt;/parameter&gt;
  &lt;/parameters&gt;
  </code></pre>
  
  <p>Here's the way I generate the package :</p>
  
  <pre><code>MsBuild MyWebService.csproj /T:Package /P:PackageLocation="c:\somewhere\package.zip" /P:IncludeAppPool=true /P:IncludeIisSettings=true
  </code></pre>
  
  <p>Here's the generated archive.xml file :</p>
  
  <pre><code>&lt;sitemanifest MSDeploy.ObjectResolver.dirPath="Microsoft.Web.Deployment.DirPathObjectResolver" MSDeploy.ObjectResolver.filePath="Microsoft.Web.Deployment.FilePathObjectResolver"&gt;
    &lt;appHostConfig path="Default Web Site/MyWebService" MSDeploy.path="2" MSDeploy.MSDeployLinkName="Child1" MSDeploy.MSDeployKeyAttributeName="path" MSDeploy.MSDeployProviderOptions="some stuff"&gt;
      &lt;application path="/MyWebService" MSDeploy.path="2" applicationPool="DefaultAppPool" MSDeploy.applicationPool="1" enabledProtocols="http" MSDeploy.enabledProtocols="1" serviceAutoStartEnabled="false" MSDeploy.serviceAutoStartEnabled="1" serviceAutoStartProvider="" MSDeploy.serviceAutoStartProvider="1" MSDeploy.MSDeployLinkName="PathElement" MSDeploy.MSDeployKeyAttributeName="path"&gt;
        &lt;virtualDirectoryDefaults path="" MSDeploy.path="1" physicalPath="" MSDeploy.physicalPath="9" userName="" MSDeploy.userName="1" password="" MSDeploy.password="1" logonMethod="ClearText" MSDeploy.logonMethod="1" allowSubDirConfig="true" MSDeploy.allowSubDirConfig="1" MSDeploy.MSDeployLinkName="virtualDirectoryDefaults" /&gt;
        &lt;virtualDirectory path="/" MSDeploy.path="2" physicalPath="C:\somewhere\MyWebService" MSDeploy.physicalPath="8" userName="" MSDeploy.userName="1" password="" MSDeploy.password="1" logonMethod="ClearText" MSDeploy.logonMethod="1" allowSubDirConfig="true" MSDeploy.allowSubDirConfig="1" MSDeploy.MSDeployKeyAttributeName="path" /&gt;
      &lt;/application&gt;
    &lt;/appHostConfig&gt;
    &lt;contentPath path="C:\somewhere\MyWebService\obj\Debug\Package\PackageTmp" MSDeploy.path="2" MSDeploy.MSDeployLinkName="Child2" MSDeploy.MSDeployKeyAttributeName="path" MSDeploy.MSDeployProviderOptions="some other stuff"&gt;
      &lt;MSDeploy.dirPath path="C:\somewhere\MyWebSerivce\obj\Debug\Package\PackageTmp" MSDeploy.MSDeployLinkName="contentPath" /&gt;
    &lt;/contentPath&gt;
    &lt;setAcl path="C:\somewhere\MyWebService\obj\Debug\Package\PackageTmp" MSDeploy.path="2" isDest="AA==" MSDeploy.isDest.Type="Microsoft.Web.Deployment.DeploymentObjectBooleanAttributeValue" setAclUser="" MSDeploy.setAclUser="1" setAclAccess="Read" MSDeploy.setAclAccess="1" MSDeploy.MSDeployLinkName="Child3" MSDeploy.MSDeployKeyAttributeName="path" MSDeploy.MSDeployProviderOptions="still some stuff" /&gt;
    &lt;setAcl path="C:\somewhere\MyWebService\obj\Debug\Package\PackageTmp" MSDeploy.path="2" isDest="AA==" MSDeploy.isDest.Type="Microsoft.Web.Deployment.DeploymentObjectBooleanAttributeValue" setAclUser="anonymousAuthenticationUser" MSDeploy.setAclUser="1" setAclAccess="Read" MSDeploy.setAclAccess="1" MSDeploy.MSDeployLinkName="Child4" MSDeploy.MSDeployKeyAttributeName="path" MSDeploy.MSDeployProviderOptions="final stuff I guess" /&gt;
  &lt;/sitemanifest&gt;
  </code></pre>
  
  <p>Here's the generated parameters.xml :</p>
  
  <pre><code>&lt;parameters&gt;
    &lt;parameter name="IIS Web Application Name" defaultValue="Default Web Site/MyWebService" tags="IisApp"&gt;
      &lt;parameterEntry kind="ProviderPath" scope="AppHostConfig" match="^Default\ Web\ Site/MyWebService$" /&gt;
      &lt;parameterEntry kind="ProviderPath" scope="contentPath" match="^C:\\somewhere\\MyWebService\\obj\\Debug\\Package\\PackageTmp$" /&gt;
      &lt;parameterEntry kind="ProviderPath" scope="setAcl" match="^C:\\somewhere\\MyWebService\\obj\\Debug\\Package\\PackageTmp$" /&gt;
      &lt;parameterEntry kind="ProviderPath" scope="IisApp" match="@defaultValue" /&gt;
      &lt;parameterEntry kind="ProviderPath" scope="setAcl" match="@defaultValue" /&gt;
    &lt;/parameter&gt;
    &lt;parameter name="IIS Web Application Pool Name" defaultValue="DefaultAppPool"&gt;
      &lt;parameterEntry kind="DeploymentObjectAttribute" scope="application" match="application[@applicationPool='DefaultAppPool']/@applicationPool" /&gt;
    &lt;/parameter&gt;
    &lt;parameter name="IisVirtualDirectoryPhysicalPath" defaultValue="C:\somewhere\MyWebService" tags="PhysicalPath"&gt;
      &lt;parameterEntry kind="DestinationVirtualDirectory" scope=".*" match="^C:\\somewhere\\MyWebService$" /&gt;
    &lt;/parameter&gt;
    &lt;parameter name="Configuration Connection String" defaultValue="Some real Connection String in there"&gt;
      &lt;parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add[@key='ConfigurationSQLConnectionString']/@value" /&gt;
    &lt;/parameter&gt;
    &lt;parameter name="Application Pool" description="Application pool for this site" defaultValue="MyOwnAppPool"&gt;
      &lt;parameterEntry kind="DeploymentObjectAttribute" scope="application" match="/application/@applicationPool" /&gt;
    &lt;/parameter&gt;
  &lt;/parameters&gt;
  </code></pre>
  
  <p>And finally, here's the command I launch to deploy the package :</p>
  
  <pre><code>msdeploy.exe -verb:sync -allowUntrusted -enableLink:AppPoolExtension -source:package="c:\somewhere\Package.zip" -dest:auto,computerName="https://destinationserver:8172/MsDeploy.axd?site=WebSite_Deployment",userName="destinationserver\deploymentUser",password="shouldKeepItSecret",authType="basic" -setParam:name="IIS Web Application Name",value="WebSite_Deployment/MyWebService" -setParam:name="Configuration Connection String",value="The Real Connection String" -setParam:name="Application Pool",value="FinalAppPool" -setParam:name="IIS Web Application Pool Name",value="FinalAppPool" -verbose
  </code></pre>
  
  <p>I get the following log : </p>
  
  <pre><code>Verbose: Parameter entry 'IIS Web Application Pool Name/1' is applicable to 'sitemanifest/appHostConfig[@path='Default Web Site/MyWebService']/application[@path='/MyWebService']' because of its scope.
  Verbose: Parameter entry 'Application Pool/1' is applicable to 'sitemanifest/appHostConfig[@path='Default Web Site/MyWebService']/application[@path='/MyWebService']' because of its scope.
  </code></pre>
  
  <p>But finally, the application pool that is set <strong>DefaultAppPool</strong> (and not <strong>FinalAppPool</strong> as expected). I first thought that msdeploy took the default application pool value for the parameter "IIS Web Application Pool Name". but it always take DefaultAppPool.
  I just don't understand why.</p>
  
  <p>As you can see, I'm using basic authentication with a non administrator account. I've activated Management Delegation Service on destinationServer to delegate contentPath, iisApp and setAcl to current user, and createApp and appHostConfig to WDeployConfigWriter.</p>
  
  <p>The fact that I added the parameter "Application Pool" is <a href="https://stackoverflow.com/questions/4023762/set-application-pool-for-package-using-msdeploy">because I found this here</a>.
  But even if I keep only one of those two parameters (Application Pool and IIS Web Application Pool Name"), the 2nd one is always in the archive.xml because of the msbuild package parameter IncludeIisSettings=true. And the result is the same.</p>
  
  <p>It doesn't seem to be a right issue, as long as the application pool is <em>really</em> set by msdeploy. It's just that it doesn't take the provided application pool.</p>
  
  <p>We also have a similar problem for Enable Protocols.</p>
  
  <p>Sorry for the length, but I wanted to be exhaustive.</p>