5

I have 3 MSBUild scripts for deployment, 1 for deploying UI 1 for deploying a couple of web services. 1 for deploying backend services.

Now I would like to create a one click deployment MSBuild script, which would call all the above 3 scripts, which can be executed from a TeamCity server.

So how can I call these three MSBuild scripts from a different MSBuild Script.

Pradeep
  • 78
  • 1
  • 2
  • 8

3 Answers3

7

There is a MSBuild MSBuild task.

OregonGhost
  • 23,359
  • 7
  • 71
  • 108
0

In MSBuild 4.0 an option might be to conditionally import the 3 project files into your one click deployment MSBuild script:

<Import Project="ProjectPath1" Condition="'$(DeployUI)'!=''" />
<Import Project="ProjectPath2" Condition="'$(DeployWebServices)'!=''" />
<Import Project="ProjectPath3" Condition="'$(DeployBackendServices)'!=''" />

<Target Name="DeployTheWorld">
    <Message Text="Deploying..." />
</Target>

Then use the AfterTargets feature on the targets you wish to run in your separate project files that you have imported:

  <Target Name="DeployUI" AfterTargets="DeployTheWorld">
    <Message Text="Hello from DefaultAfterTarget"/>
  </Target>

This will give you flexibly in customising the deployment from within TeamCity.

user1592890
  • 101
  • 1
-1

I have not used TeamCity Server, but one possible alternate solution is to combine the three build scripts into one script. And put tasks of the three separate scripts into separate targets in the master build file. So, instead of the three separate build scripts, you have one build script with three targets, namely deployUI, deployServices, deployBackend. Untested sample below:

    <?xml version="1.0" encoding="utf-8" ?>
    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="DefaultTarget" ToolsVersion="3.5">

    <Target Name="DefaultTarget">
            <CallTarget Targets="deployUI" ContinueOnError="false"></CallTarget>
            <CallTarget Targets="deployServices" ContinueOnError="false"></CallTarget>
            <CallTarget Targets="deployBackend" ContinueOnError="false"></CallTarget> 
    </Target>

    <Target Name="deployUI">
            <!-- Put UI deployment tasks here -->
    </Target>

    <Target Name="deployServices">
            <!-- Put Services deployment tasks here -->
    </Target>

    <Target Name="deployBackend">
            <!-- Put Backend deployment tasks here -->
    </Target>
</Project>
Punit Vora
  • 5,052
  • 4
  • 35
  • 44
  • This is a valid option to merge all the 3 components, but I want the ability to deploy the components independently if I choose to, an do not want to duplicate the build script content in two scripts. – Pradeep Aug 04 '09 at 15:08
  • You have the ability to deploy components individually by using conditional statements within the build file. If you use conditional statements, then you don't have to maintain duplicate script files either. just provide the correct target while calling the build file and you are done. – Punit Vora Aug 04 '09 at 19:26
  • Sidenote: I am not sure how the accepted answer helps? In the mentioned task I do not see a way to call build files/scripts which is what your questions asks for. The MSBuild task allows you to build projects with some options, but you wanted to build using build files which most likely will do other things than just compile and deploy (for example updating related config files). In that case using just the MSBuild task will not work. Let me know if I am missing something. – Punit Vora Aug 04 '09 at 19:31