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)
    [sourcecode language=”html”]
    <?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>
    [/sourcecode]
  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:
    [sourcecode language=”html”]
    <Import Project="wspbuilder.Targets" />
    [/sourcecode]
  5. Uncomment the AfterBuild tag and add the following statements; remember to specify the adjust CallTarget!
    [sourcecode language=”html”]
    <Target Name="AfterBuild">
    <CallTarget Targets="BuildSharePointPackage" />
    </Target>
    [/sourcecode]
Share

Leave a Reply

Your email address will not be published.