MSBuild Sidekick Walkthroughs


Walkthrough 1 : reating project "from scratch"

In this walkthrough you will create basic MSBuild project. This project will remove all object (*.obj) and precompiled header (*.pch) files recursively from given folder; if the folder is not passed as a parameter, folder defaults to the project location folder (such script may be useful to remove temprary files from C++ build folders).

Basic knowledge of MSBuild schema is assumed for this walkthrough.


Step1 : Create new empty project
  • Click on File->New menu or Standard toolbar New button whereupon new project will be created

Step2 : Add property group
  • Select project element in project tree view by clicking on it
  • Right click on Project element and click on Add PropertyGroup

Step3 : Add property (to specify folder to clean up)
  • Select property group element in project tree view by clicking on it
  • Right click on PropertyGroup element and click on Add Property

Step4 : Assign condition and default value to the property (so default will be supplied if no external value is passed)
  • Select Property1 element in project tree by clicking on it
  • On Properties tab, click on Check for empty value button on the tab toolbar
  • On Properties tab, set Value property to "$(MSBuildProjectDirectory)"

Step5 : Add item group
  • Select project element in project tree view by clicking on it
  • Right click on Project element and click Add ItemGroup

Step6 : Add item (to specify files to be deleted by the project)
  • Select item group element in project tree view by clicking on it
  • Right click on ht ItemGroup element and click Add Item
  • Select element item in project tree view by clicking on it
  • On Properties tab, set Include property to "$(Property1)\**\*.obj; $(Property1)\**\*.pch"

Step7 : Add target
  • Select project element in project tree view by clicking on it
  • Right click on Project element and click Add Target

Step8 : Add Delete task to the target
  • Select target element in project tree view by clicking on it
  • Right click on Target element and click Add Task
  • Select Delete task in Add Task dialog list
  • Click Add button
  • Click Close button

Step9 : Assign Delete task input parameters
  • Select task element in project tree view by clicking on it
  • On Properties tab, set Files property to "@(Item)"

Step10 : Assign Delete task output parameters
  • Select task element in project tree view by clicking on it
  • Right click on Delete task element and click on DeletedFiles from Add Output submenu
  • Select task output parameter element in project tree view by clicking on it
  • On Properties tab, set PropertyName property to "deleted"

Step11 : Add Message task (to print the deleted files list)
  • Right click on Target element from project tree and choose Add Task
  • Select Message task in Add Task dialog tasks list
  • Click Add button
  • Click Close button

Step12 : Assign Message task input parameters
  • Select task element in project tree view by clicking on it
  • On Properties tab, set Text property to "$(deleted)"

Step13 : Set project default target
  • Select project element in project tree view by clicking on it
  • On Properties tab, set DefaultTargets property to "Target1"

Step14 : Save project file
  • Click File->Save menu or Standard toolbar Save Project button

Upon completing the walkthrough, the following MSBuild project was created:

    1 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Target1">

    2     <PropertyGroup>

    3         <Property1 Condition="'$(Property1)' == ''">$(MSBuildProjectDirectory)</Property1>

    4     </PropertyGroup>

    5     <ItemGroup>

    6         <Item Include="$(Property1)\**\*.obj;$(Property1)\**\*.pch" />

    7     </ItemGroup>

    8     <Target Name="Target1">

    9         <Delete Files="@(Item)">

   10             <Output TaskParameter="DeletedFiles" PropertyName="deleted"/>

   11         </Delete>

   12         <Message Text="$(deleted)" />

   13     </Target>

   14 </Project>

Back to MSBuild Sidekick product page.


© 2006-2016 Attrice Corporation. Last updated 30-Dec-2015 Contact us