如何通过BTDF在IIS不同应用下部署两个服务并参数化IISMetabasePath
使用BTDF将服务部署到不同IIS网站的解决方案
要实现将两个服务部署到IIS的不同网站中,你需要为每个VDirList条目添加自定义元数据,并通过自定义MSBuild目标动态生成对应的IISMetabasePath。以下是具体步骤:
1. 为VDirList添加AppId元数据
在你的VDirList配置中,为每个服务添加<AppId>元素,指定目标IIS网站的ID(例如1、2等):
<ItemGroup> <VDirList Include="*"> <Vdir>GetCTCNumber</Vdir> <Physdir>..\CTCNumberService</Physdir> <AppPool>CTCNumberAppPool</AppPool> <AppPoolNetVersion>v4.0</AppPoolNetVersion> <AppId>1</AppId> <!-- 目标IIS网站ID --> </VDirList> <VDirList Include="*"> <Vdir>GetCTCusingTICCode</Vdir> <Physdir>..\TICCodeService</Physdir> <AppPool>TICCodeAppPool</AppPool> <AppPoolNetVersion>v4.0</AppPoolNetVersion> <AppId>2</AppId> <!-- 目标IIS网站ID --> </VDirList> </ItemGroup>
2. 自定义MSBuild目标处理每个VDir条目
在你的.btdfproj文件中,覆盖默认的DeployIIS目标,实现逐个处理每个VDirList条目,并为每个条目生成对应的IISMetabasePath:
<!-- 覆盖默认的DeployIIS目标,批量处理每个VDir条目 --> <Target Name="DeployIIS" DependsOnTargets="BeforeDeployIIS"> <MSBuild Projects="$(MSBuildProjectFile)" Targets="ProcessSingleVDir" Properties="VDirItem=%(VDirList.Identity);AppId=%(VDirList.AppId)" /> </Target> <!-- 处理单个VDir条目的辅助目标 --> <Target Name="ProcessSingleVDir"> <PropertyGroup> <!-- 根据当前条目的AppId生成IIS元数据库路径 --> <IISMetabasePath>IIS://localhost/w3svc/$(AppId)/Root</IISMetabasePath> <!-- 提取当前条目的元数据 --> <CurrentVdir>$([System.String]::Copy('%(VDirList.Vdir)'))</CurrentVdir> <CurrentPhysdir>$([System.String]::Copy('%(VDirList.Physdir)'))</CurrentPhysdir> <CurrentAppPool>$([System.String]::Copy('%(VDirList.AppPool)'))</CurrentAppPool> <CurrentAppPoolNetVersion>$([System.String]::Copy('%(VDirList.AppPoolNetVersion)'))</CurrentAppPoolNetVersion> </PropertyGroup> <!-- 调用BTDF内置的CreateVirtualDirectory目标创建虚拟目录 --> <MSBuild Projects="$(MSBuildProjectFile)" Targets="CreateVirtualDirectory" Properties="Vdir=$(CurrentVdir);Physdir=$(CurrentPhysdir);AppPool=$(CurrentAppPool);AppPoolNetVersion=$(CurrentAppPoolNetVersion);IISMetabasePath=$(IISMetabasePath)" /> </Target>
说明
- 确保目标IIS服务器上已经存在对应
AppId的网站(例如ID为1和2的网站)。 - 该方案通过MSBuild批处理功能,为每个
VDirList条目单独生成IISMetabasePath,从而实现将不同服务部署到不同的IIS网站中。 - 自定义目标会保留BTDF原有的虚拟目录创建逻辑,仅动态替换了目标网站路径。
内容的提问来源于stack exchange,提问作者Nemo
相关产品推荐
相关产品推荐

