0

I have added the following code to a VisualC++ 2010 .vcxproj file just inside the first <project> tag:

<PropertyGroup>
  <PilotStationDirectory>\..\..\PilotStation\PilotStationApp\$(Configuration)</PilotStationDirectory>
</PropertyGroup>
<ItemGroup>
  <MySourceFiles Include="$(TargetName).dll;$(TargetName).lib;$(TargetName).pdb" />
</ItemGroup>
<Target Name="AfterBuild">
  <MakeDir Directories="$(PilotStationDirectory)" />
  <Copy SourceFiles="@(MySourceFiles)" DestinationFolder="$(PilotStationDirectory)" />
  <Message Text="###I AM HERE###" />
</Target>

I have set the "MSBuild project build output/log verbosity" to "Normal". I'm not seeing anything in the log and no files are being copied.

Is there something else that I have to do to make this work?

Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288

1 Answers1

2

A project can have only one AfterBuild target. Placement is critical, make sure it appears after any <Import> directive so you can be sure it is last and the default one is overridden. Bump up the priority of the <Message> so you can always see it.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   ...
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   ...
   <Target Name="AfterBuild">
     <Message Importance="High" Text="It works"/>
   </Target>
</Project>

Output:

1>------ Build started: Project: ConsoleApplication317, Configuration: Debug Win32 ------
1>  ConsoleApplication317.vcxproj -> C:\projects2\ConsoleApplication317\Debug\ConsoleApplication317.exe
1>  It works
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • @HansPassant Any different advice for `BeforeBuild`? I can't get that one to work now. – Jonathan Mee Nov 06 '14 at 19:54
  • @HansPassant Well I'm just not sure what the problem is with my `BeforeBuild`. I've opened up a separate question on it, if you have any other insight: http://stackoverflow.com/questions/26789417/msbuild-beforebuild-step – Jonathan Mee Nov 06 '14 at 21:09