Question

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)

Was it helpful?

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>

OTHER TIPS

I ended up with this pre-build-event code. Toms solution is probably better though.

echo off

set THEME_REGKEY=HKLM\Software\Microsoft\MSBuild\4.0
set THEME_REGVAL=MSBuildOverrideTasksPath

REM Check for presence of key first.
reg query %THEME_REGKEY% /v %THEME_REGVAL% 2>nul || (echo No theme name present! & exit /b 1)

REM query the value. pipe it through findstr in order to find the matching line that has the value. only grab token 3 and the remainder of the line. %%b is what we are interested in here.
set THEME_NAME=
for /f "tokens=2,*" %%a in ('reg query %THEME_REGKEY% /v %THEME_REGVAL% ^| findstr %THEME_REGVAL%') do (
    set THEME_NAME=%%b
)

REM Possibly no value set
if not defined THEME_NAME (echo No theme name present! & exit /b 1)

REM replace any spaces with +
set THEME_NAME=%THEME_NAME: =+%

if errorlevel 1 goto BuildEventFailed
%THEME_NAME%MSBuild  "$(SolutionDir)Web\Web.csproj" /t:Build;Package /p:Configuration=$(Configuration)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top