我一直在浏览几十个站点,以帮助我使用 MsDeploy 将 Web 服务部署到 IIS。我需要创建应用程序,修改应用程序池并启用协议,并更新 appSetting(包含连接字符串,不要问我为什么)。
我可以做所有这些,除了应用好的应用程序池。
这是我添加到项目中的 parameters.xml 文件:
<parameters>
<parameter tags="IisApp" defaultValue="Default Web Site/MyWebService" name="IIS Web Application Name">
<parameterEntry match="@defaultValue" scope="IisApp" kind="ProviderPath"/>
<parameterEntry match="@defaultValue" scope="setAcl" kind="ProviderPath"/>
</parameter>
<parameter name="Configuration Connection String" defaultValue="Some real Connection String in there" tags="">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add[@key='ConfigurationSQLConnectionString']/@value" />
</parameter>
<parameter name="Application Pool" defaultValue="MyOwnAppPool" description="Application pool for this site">
<parameterEntry kind="DeploymentObjectAttribute" scope="application" match="/application/@applicationPool" />
</parameter>
</parameters>
这是我生成包的方式:
MsBuild MyWebService.csproj /T:Package /P:PackageLocation="c:\somewhere\package.zip" /P:IncludeAppPool=true /P:IncludeIisSettings=true
这是生成的 archive.xml 文件:
<sitemanifest MSDeploy.ObjectResolver.dirPath="Microsoft.Web.Deployment.DirPathObjectResolver" MSDeploy.ObjectResolver.filePath="Microsoft.Web.Deployment.FilePathObjectResolver">
<appHostConfig path="Default Web Site/MyWebService" MSDeploy.path="2" MSDeploy.MSDeployLinkName="Child1" MSDeploy.MSDeployKeyAttributeName="path" MSDeploy.MSDeployProviderOptions="some stuff">
<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">
<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" />
<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" />
</application>
</appHostConfig>
<contentPath path="C:\somewhere\MyWebService\obj\Debug\Package\PackageTmp" MSDeploy.path="2" MSDeploy.MSDeployLinkName="Child2" MSDeploy.MSDeployKeyAttributeName="path" MSDeploy.MSDeployProviderOptions="some other stuff">
<MSDeploy.dirPath path="C:\somewhere\MyWebSerivce\obj\Debug\Package\PackageTmp" MSDeploy.MSDeployLinkName="contentPath" />
</contentPath>
<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" />
<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" />
</sitemanifest>
这是生成的 parameters.xml :
<parameters>
<parameter name="IIS Web Application Name" defaultValue="Default Web Site/MyWebService" tags="IisApp">
<parameterEntry kind="ProviderPath" scope="AppHostConfig" match="^Default\ Web\ Site/MyWebService$" />
<parameterEntry kind="ProviderPath" scope="contentPath" match="^C:\\somewhere\\MyWebService\\obj\\Debug\\Package\\PackageTmp$" />
<parameterEntry kind="ProviderPath" scope="setAcl" match="^C:\\somewhere\\MyWebService\\obj\\Debug\\Package\\PackageTmp$" />
<parameterEntry kind="ProviderPath" scope="IisApp" match="@defaultValue" />
<parameterEntry kind="ProviderPath" scope="setAcl" match="@defaultValue" />
</parameter>
<parameter name="IIS Web Application Pool Name" defaultValue="DefaultAppPool">
<parameterEntry kind="DeploymentObjectAttribute" scope="application" match="application[@applicationPool='DefaultAppPool']/@applicationPool" />
</parameter>
<parameter name="IisVirtualDirectoryPhysicalPath" defaultValue="C:\somewhere\MyWebService" tags="PhysicalPath">
<parameterEntry kind="DestinationVirtualDirectory" scope=".*" match="^C:\\somewhere\\MyWebService$" />
</parameter>
<parameter name="Configuration Connection String" defaultValue="Some real Connection String in there">
<parameterEntry kind="XmlFile" scope="\\web.config$" match="/configuration/appSettings/add[@key='ConfigurationSQLConnectionString']/@value" />
</parameter>
<parameter name="Application Pool" description="Application pool for this site" defaultValue="MyOwnAppPool">
<parameterEntry kind="DeploymentObjectAttribute" scope="application" match="/application/@applicationPool" />
</parameter>
</parameters>
最后,这是我为部署包而启动的命令:
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
我得到以下日志:
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.
但最后,设置DefaultAppPool的应用程序池(而不是预期的FinalAppPool)。我首先认为 msdeploy 为参数“IIS Web 应用程序池名称”采用了默认应用程序池值。但它总是需要 DefaultAppPool。我只是不明白为什么。
如您所见,我使用的是非管理员帐户的基本身份验证。我在destinationServer 上激活了管理委派服务,将contentPath、iisApp 和setAcl 委派给当前用户,并将createApp 和appHostConfig 委派给WDeployConfigWriter。
我添加参数“应用程序池”的事实是因为我在这里找到了这个。但即使我只保留这两个参数中的一个(应用程序池和 IIS Web 应用程序池名称“),由于 msbuild 包参数 IncludeIisSettings=true,第二个总是在 archive.xml 中。结果是一样的。
这似乎不是一个正确的问题,只要应用程序池真的是由 msdeploy 设置的。只是它不占用提供的应用程序池。
启用协议也有类似的问题。
抱歉,篇幅较长,但我想详尽无遗。