Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio and MSBuild fire BeforeBuild differently on a WiX project

Tags:

msbuild

wix

I have a WiX (Windows installer XML) v3, project which contains references to other projects in my solution. I am using the copy task inside the BeforeBuild event of the WiX project to collect some of the output of the references projects for later use my Heat.

When I build the WiX project (not the solution) inside Visual Studio, each of the referenced projects is build before my WiX project and once they are built, the BeforeBuild event on my WiX project fires and then the WiX project itself is built. This is the behaviour I expect - I am able to access files from the bin directories of the references projects in the WiX BeforeBuild and use them as I please before the WiX project executes Candle.

The problem I am having is when I build the WiX file via MSBuild I am finding that the BeforeBuild event fires straight away BEFORE any of the referenced projects. This difference in behaviour means that I cannot make use of the outputs of the referenced projects when building from the command line.

Why is BeforeBuild executing at a different point in time when run via MSBuild on the command line to inside Visual Studio?

like image 309
Dav Evans Avatar asked Sep 03 '10 23:09

Dav Evans


People also ask

What is WiX Visual Studio?

The Visual Studio WiX toolset allows you to easily create WiX projects, edit WiX files using IntelliSense, and compile/link your project within the Visual Studio IDE. For WiX project types, see WiX Project Types. For WiX item templates, see WiX Item templates. For the WiX property pages, see WiX Project property pages.

How do I open a WiX project in Visual Studio 2019?

In Visual Studio, open your solution, and add a WiX project to it: go to the Visual Studio main menu and click File -> Add -> New Project to open the Add New Project dialog. Choose the Setup Project item in the Windows Installer XML node, specify the project name and click OK.

How do I create a Wixproj file?

A simple way to create a WIXPROJ file is to type, "msbuild projectfile. wixproj" at the command line (where "projectfile" is the name of the project file). If WiX has been installed, Visual Studio will create a standard msbuild project file. WIXPROJ files can also be created and edited using a text editor.


1 Answers

If you are building inside Visual Studio, the solution dependencies (which can be explicit or based on the project references) are used to determine which projects need to be built and a separate build is kicked off for each of them. This is necessary since solutions can also contain projects that are not built using MSBuild and other projects have explicit dependencies set in the solution for them. The side effect is that each project is treated as a stand-alone build, thus ensuring the right BeforeBuild order for you..

If you are building from the command line using MSBuild, the dependency projects are resolved (and built if necessary) during the ResolveReferences target. The BeforeBuild target and PreBuild event (executed from the PreBuildEvent target) are both performed before the ResolveReferences target. Thus the dependent project BeforeBuild target ends up executing before the build for the dependency project is kicked off.

Note that from a point of view of a single project, BeforeBuild target does make sense to be executed before resolving dependencies, as the dependency resolution might itself depend on the BeforeBuild target output. For example, BeforeBuild might execute a custom script to get the latest copy of any dependency projects from the SCM.

like image 158
Franci Penov Avatar answered Oct 23 '22 04:10

Franci Penov