Add “After build” event in project file Visual Studio

After build events can be added to the property page of a visual studio project. You can also add your own “targets” file to the afterbuild (or beforebuild) in the project file itself. Use the following method:

  1. Add a targets file to your project with the following contents (for example)
    <?xml version="1.0" encoding="utf-8" ?>
    <Project DefaultTargets="WSPBuild"
       xmlns=http://schemas.microsoft.com/developer/msbuild/2003>
       <PropertyGroup>
          <WSPBuilderPath>"....ToolsWSPBuilder.exe"</WSPBuilderPath>
       </PropertyGroup>
       <Target Name="WSPBuild">
          <Exec Command="cd $(ProjectDir)" Outputs="null" />
          <Message Text="Executing WSP Builder in directory $(ProjectDir)"/>
          <Exec Command="$(WSPBuilderPath) "/>
       </Target>
    </Project>
    
  2. Unload the project file
  3. Right click the project file and choose Edit…..
  4. Add an import tag below the last import tag in the projectfile:
    <Import Project="wspbuilder.Targets" />
    
  5. Uncomment the AfterBuild tag and add the following statements; remember to specify the adjust CallTarget!
    <Target Name="AfterBuild">    
         <CallTarget Targets="BuildSharePointPackage" />
    </Target> 
    
Share

Leave a Reply

Your email address will not be published. Required fields are marked *