複数の環境にコードをデプロイするためのビルド スクリプトを作成しようとしています。コードは次のとおりです。
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<TargetEnv>Production</TargetEnv>
</PropertyGroup>
<ItemGroup Condition="'$(TargetEnv)' == 'Integration'">
<Server Include="int1">
<ip>172.0.0.1</ip>
</Server>
</ItemGroup>
<ItemGroup Condition="'$(TargetEnv)' == 'Production'">
<Server Include="prod1">
<ip>172.0.2.1</ip>
</Server>
<Server Include="prod2">
<ip>172.0.2.2</ip>
</Server>
</ItemGroup>
<Target Name="Deploy">
<CallTarget Targets="DeployIntegration" />
<CallTarget Targets="DeployServers" />
</Target>
<Target Name="DeployIntegration" Condition="'$(TargetEnv)' == 'Integration'" Outputs="%(Server.Identity)">
<Message Text="= specific int server thing need access to variable %(Server.Identity) =" Importance="high" />
</Target>
<Target Name="DeployServers" Condition="'$(TargetEnv)' != 'Integration'" Outputs="%(Server.Identity)">
<Message Text="= specific prod thing here need access to variable %(Server.Identity) =" Importance="high" />
</Target>
<Target Name="RemoveServerFromLoadBalancer" AfterTargets="DeployServers" Condition="'$(TargetEnv)' != 'Integration'">
<Message Text="= removing %(Server.Identity) from load balancer =" Importance="high" />
</Target>
<Target Name="IgnoreRemoveServerFromLoadBalancer" AfterTargets="DeployServers" Condition="'$(TargetEnv)' == 'Integration'">
<Message Text="= ignore removing %(Server.Identity) from load balancer =" Importance="high" />
</Target>
<Target Name="CopyFilesAndCreateFolderLinks" AfterTargets="RemoveServerFromLoadBalancer;IgnoreRemoveServerFromLoadBalancer">
<Message Text=" = creating and copying files %(Server.Identity) =" Importance="high" />
</Target>
<Target Name="SetWebFarmServerName" AfterTargets="UpdateWebConfig" Condition="'$(TargetEnv)' != 'Integration'">
<Message Text=" = app setting CMSWebFarmServerName set to %(Server.Identity) =" Importance="high" />
</Target>
<Target Name="DisableWebFarmForIntegration" AfterTargets="UpdateWebConfig" Condition="'$(TargetEnv)' == 'Integration'">
<Message Text=" = Disabled webfarm setting for Integration - %(Server.Identity) =" Importance="high" />
</Target>
<Target Name="AddBackToLoadBalancer" AfterTargets="DisableWebFarmForIntegration" Condition="'$(TargetEnv)' != 'Integration'">
<Message Text=" = Putting server %(Server.Identity) back on load balancer =" Importance="high" />
</Target>
</Project>
このコードは xml (11.0 フォルダーに保存されている) ファイルにあり、msbuild コマンドを使用して実行します。
C:\Program Files (x86)\Microsoft Visual Studio 11.0>msbuild buildtest.xml /t:Deploy
本番用のビルド タスクを実行すると、このコードはこれを返します。
DeployServers:
= specific prod thing here need access to variable prod1 =
DeployServers:
= specific prod thing here need access to variable prod2 =
RemoveServerFromLoadBalancer:
= removing prod1 from load balancer =
= removing prod2 from load balancer =
CopyFilesAndCreateFolderLinks:
= creating and copying files prod1 =
= creating and copying files prod2 =
私は基本的に、統合している場合、ロードバランサー関連のタスクなどの特定のターゲットを実行しないようにしたいと考えています。これは、マシンが 1 つしかないためです。私は考えています、返される値は次のようになるはずです:
DeployServers:
= specific prod thing here need access to variable prod1 =
RemoveServerFromLoadBalancer:
= removing prod1 from load balancer =
CopyFilesAndCreateFolderLinks:
= creating and copying files prod1 =
DeployServers:
= specific prod thing here need access to variable prod2 =
RemoveServerFromLoadBalancer:
= removing prod2 from load balancer =
CopyFilesAndCreateFolderLinks:
= creating and copying files prod2 =
長い投稿で申し訳ありませんが、この msbuild は少しトリッキーです。ご意見をお待ちしております。