Question

I want to perform some copy actions on the build machine (but not on the developer machines)

  • after a build is performed and
  • before the integration tests run.

How do I do that?

Perhaps, I should split the question up into sub-questions and give some examples.

Question 1: What do I need to do so that the MSBuild script detects that it is being executed on the build machine and therefore does a copy operation? Do I adapt the *.csproj file? Do I do something within the Build Definition file? The build server is part of our TFS 2010 backend.

Question 2: What variable do I need to use to reference the build folder on the build machine? The absolute path is

C:\Builds\1\ProjectX\Continous Integration\

I need to copy some files which are under version control and end up in the Sources folder to the Binaries folder.

C:\Builds\1\ProjectX\Continous Integration\Binaries
C:\Builds\1\ProjectX\Continous Integration\Sources
C:\Builds\1\ProjectX\Continous Integration\TestResults
Was it helpful?

Solution

Whatever you are automating the build with ought to be able to pass a property through to MSBuild. On the command line you do something like:

msbuild my.proj /p:RunningOnBuildMachine=true

In your script you can then use a condition based on $(RunningOnBuildMachine) == 'true' to trigger the interim step. Alternatively there is already an inbuilt variable $(BuildingInsideVisualStudio) which tells MSBuild whether it's being called from within VS or not which may be sufficient for your needs.

As to where your output directory is, that's a bit trickier. What determines that location? Is it the CI server? If so you could try getting that to pass the output directory as a property to the script as well.

OTHER TIPS

If you are using the default build process template (DefaultTemplate.xaml) that is using Windows Workflow Foundation instead of the Upgrade Template that uses MSBuild then you can use a CopyDirectory workflow activity that is included out of the box and put it between the compilation section and the testing section of the workflow.

Which build process template are you using in TFS 2010?

Build folder:

Have you tried MSBuild reserved property MSBuildProjectDirectory?

You can acces it in the same manner as other properties, e.g. $(MSBuildProjectDirectory)\Binaries. Or did you mean something else?

If you feel comfortable with Workflows you can manipulate the existing one to do that as Ed already specified. If you want that to be part of your build process, so that you can prepare a package which you can use eventually with msdeploy you can put in your msbuild script.

1) Assuming that you have a web project file to build, you can create msbuild script with the same name as the project file with extension wpp.targets; it will get picked up by the build process, e.g. if you project is called mywebproject.csprj, the new script will be called mywebproject.wpp.targets. There you can put your targets to run after specific build in targets. About the property, you have lots of options. Paolo example is good. I normally define a default empty property which I override with the build parameters, or modify the workflow to override that property. In regular build with visual studio my parameter will be empty and I can use that as a condition of some of my targets.

2) I use a lot $(ProjectDir) and $(_PackageTempDir), when I want to include additional files to the msdeploy package. $(ProjectDir) will work for you as well. It is pointing to the folder where your project file on the build server is.

I hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top