Search code examples
visual-studio-2010visual-studiowixwebdeploybuild-events

Create deployment package during build event


I have a project "A" that needs the deployment package of a another project "B".

I want this to happen automatically so that "A" depends on "B" and in the pre-build-event of "A" the deployment package is made for "B".

I know how to do this manually (right click "B"->Build Deployment Package->build "A") and it works fine, but how to automate it as described?

("A" is actually a WIX project)


Solution

  • There are two ways to do this:

    1. Always build B's package after B is built or
    2. Always build B's package before A is built

    The advantage of the first is that A has to know less about B. The advantage of the second is that B can be built during development without the step of building the package.

    As you may know, Visual Studio projects are MSBuild projects. You can edit them in Visual Studio by choosing Unload Project and then Edit from the project's context menu in the Solution Explorer. It is often easier and sometimes necessary to add build steps this way than through the Build Events editor. If you want to leave a clue about the customization of the project file, you can add a "rem" command to Pre-build event field.

    In either of the above cases, the Package target of project B must be run before the Build target of project A. Choosing the second case above, add this MSBuild task to A's BeforeBuild target.

    <MSBuild
        Projects="relative-or-absolute/path/to/B.xxproj"
        Targets="Package">
    </MSBuild>