Question

I am running build with next targets:

  <Target Name="BeforeCompile">
    <Message Text="Build no: $(BuildNumber)" />
  </Target>

Then in between I run build (using nmake). After that I want to deploy firmware:

  <Target Name="AfterCompile">
    <MSBuild Projects="$(MSBuildProjectFile)" Targets="CustomDeployMagicFirmware" Properties="Id=1" />
  </Target>

  <Target Name="CustomDeployMagicFirmware">
    <Message Text="...Deploying bootloader files to build machine - folder: $(BuildNumber)" />
    <Exec Command='xcopy "$(SolutionRoot)\Repository\bootloader\*.axf" \\machine\bootloader\$(BuildNumber) /y /q'/>
    <Exec Command='xcopy "$(SolutionRoot)\Repository\bootloader\*.hex" \\machine\bootloader\$(BuildNumber) /y /q'/ -->
  </Target>

The problem is that in target "BeforeCompile" I get properly message output for $(BuildNumber). But later I have Message Test output like:
...Deploying bootloader files to build machine - folder:
There looks like variable $(BuildNumber) is not set anymore. Also command xcopy copies files to folder bootloader and not to folder bootloader\$(BuildNumber).

What do I do wrong? Which things can influence variable contents?

Was it helpful?

Solution

The error is in this line

<MSBuild Projects="$(MSBuildProjectFile)" Targets="CustomDeployMagicFirmware" Properties="Id=1" />

The MSBuild task spawns a new MSBuild.exe process and you are not passing the property $(BuildNumber) to the new process. Change it like below and this would work

<MSBuild Projects="$(MSBuildProjectFile)" Targets="CustomDeployMagicFirmware" Properties="Id=1;BuildNumber=$(BuildNumber)" />

OTHER TIPS

Use <CallTarget> instead of <MSBuild> to invoke your CustomDeployMagicFirmware target.

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