tags:

views:

41

answers:

1

I've been working on tacking on a deployment operations to my web project file so that I can deploy a web project from TeamCity. How can I enclose the and steps so that I do not need to repeat the condition check?

<Target Name="Deploy">
  <PropertyGroup Condition=" '$(Configuration)' == 'Development-Publish' ">
    <ScriptPath>c:\scripts\development.txt</ScriptPath>
    <DeploymentPath>\\devserver\dev</DeploymentPath>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Integration-Publish' ">
    <ScriptPath>c:\scripts\integration.txt</ScriptPath>
    <DeploymentPath>\\integrationserver\int</DeploymentPath>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Staging-Publish' ">
    <ScriptPath>c:\scripts\staging.txt</ScriptPath>
    <DeploymentPath>\\stagingserver\staging</DeploymentPath>
  </PropertyGroup>
  <PropertyGroup>
    <BeyondCompareCommand>C:\Program Files\Beyond Compare 3\BCompare.exe</BeyondCompareCommand>
    <AdditionalArguments>/silent /closescript</AdditionalArguments>
    <DeploymentCommand>"$(BeyondCompareCommand)" @"$(ScriptPath)" "$(WebProjectOutputDir)" "$(DeploymentPath)" $(AdditionalArguments)</DeploymentCommand>
  </PropertyGroup>
  <Message Condition=" '$(DeploymentPath)' != '' " Importance="high" Text="Executing Deployment with this command: $(DeploymentCommand)" />
  <Exec Condition=" '$(DeploymentPath)' != '' " Command="$(DeploymentCommand)" />
</Target>

I thought that I should have a <Target Name="DeploymentParameters"/> which <Target Name="Deploy" DependsOnTargets="DeploymentParameters"/> but unless I made a mistake, it appeared I couldn't access the properties declared in the DeploymentParameters target.

A: 
<PropertyGroup Condition=" '$(Configuration)' == 'Development-Publish' ">
  <ScriptPath>c:\scripts\development.txt</ScriptPath>
  <DeploymentPath>\\devserver\dev</DeploymentPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Integration-Publish' ">
  <ScriptPath>c:\scripts\integration.txt</ScriptPath>
  <DeploymentPath>\\integrationserver\int</DeploymentPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Staging-Publish' ">
  <ScriptPath>c:\scripts\staging.txt</ScriptPath>
  <DeploymentPath>\\stagingserver\staging</DeploymentPath>
</PropertyGroup>
<PropertyGroup>
  <BeyondCompareCommand>C:\Program Files\Beyond Compare 3\BCompare.exe</BeyondCompareCommand>
  <AdditionalArguments>/silent /closescript</AdditionalArguments>
  <DeploymentCommand>"$(BeyondCompareCommand)" @"$(ScriptPath)" "$(WebProjectOutputDir)" "$(DeploymentPath)" $(AdditionalArguments)</DeploymentCommand>
</PropertyGroup>
<Target Name="Deploy" Condition=" '$(DeploymentPath)' != '' " >
  <Message Importance="high" Text="Executing Deployment with this command: $(DeploymentCommand)" />
  <Exec Command="$(DeploymentCommand)" />
</Target>
Dave