Visual Studio and MSBuild Fire BeforeBuild differently in WiX project

I have WiX (Windows installer XML) v3, a project that contains links to other projects in my solution. I use the copy task inside the BeforeBuild event of a WiX project to collect some of the results of link projects for later use. Heat .

When I create a WiX project (and not a solution) inside Visual Studio, each of the referenced projects is built before my WiX project, and after they are created, the BeforeBuild event occurs in my WiX project, and then the WiX project itself is built-in. This is the behavior I expect - I can access the files from the bin directories of the link projects in WiX BeforeBuild and use them, as I wish, before the WiX Candle project runs.

The problem I am facing is when I create a WiX file through MSBuild . I found that the BeforeBuild event is fired right before BEFORE any of the referenced projects. This difference in behavior means that I cannot use the project outputs referenced when creating from the command line.

Why is BeforeBuild executed at a different point in time when running through MSBuild on the command line inside Visual Studio?

+7
msbuild wix
source share
1 answer

If you are building inside Visual Studio, dependencies for the solution (which can be explicit or based on project references) are used to determine which projects need to be built, and a separate assembly is opened for each of them. This is necessary because solutions may also contain projects that are not built using MSBuild, while other projects have explicit dependencies set in the solution for them. A side effect is that each project is considered as a standalone assembly, which ensures the correct BeforeBuild order for you.

If you are building from the command line using MSBuild, dependency projects are resolved (and if necessary created) during the ResolveReferences target. The BeforeBuild target and PreBuild (executed from the PreBuildEvent target) are executed before the ResolveReferences target. Thus, the BeforeBuild target project ends with execution before the build for the dependency project is started.

Please note that from the point of view of one project, the BeforeBuild target makes sense before resolving the dependencies, since resolving the dependencies may depend on the BeforeBuild target output. For example, BeforeBuild can execute a custom script to get the latest copy of any dependency projects from SCM .

+8
source share

All Articles