Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild: directory.build.props and directory.build.targets does not work with *.wixproj

Tags:

msbuild

wix

directory.build.props and directory.build.targets is not working with Windows Installer Wix projects. *.wixproj

How to fix this issue?

like image 305
Xavier John Avatar asked Jan 26 '23 05:01

Xavier John


1 Answers

Background

The implicit import of directory.build.props and directory.build.targets is an intrinsic feature of MSBuild 15.0+. It does not have to be in the new SDK project style format for it to work. The magic happens via the import of microsoft.common.props, which SDK style projects do automatically and most older style projects include as the first import in the project file. This is documented here.

Unfortunately, WiX projects do not include this import, which is why it’s not being picked up (as shown here in the Votive source). I can't say why, but there might be a reason for microsoft.common.props being excluded.

Since it's unclear if importing microsoft.common.props may cause you grief, the recommended approach is the import the extensions manually using the new GetPathOfFileAbove function. You only need to do this once.

Solution

  1. Unload your project with Right-click the project → Unload {name}…
  2. Right-click the project → Edit {name}…
  3. Add the following at Line 3 (should be the first element in the <Project>):

    <Import Project="$([MSBuild]::GetPathOfFileAbove(directory.build.props))"
            Condition="Exists('$([MSBuild]::GetPathOfFileAbove(directory.build.props))')" />
    
  4. Add the following at the bottom of the file before the WiX targets are imported:

    <Import Project="$([MSBuild]::GetPathOfFileAbove(directory.build.targets))"
            Condition="Exists('$([MSBuild]::GetPathOfFileAbove(directory.build.targets))')" />
    

If you need to hook into the WiX build process or targets, use the CustomBeforeWixTargets and CustomAfterWixTargets build properties, which might refer to the directory.build.targets file itself via the MSBuildThisFileFullPath reserved property. This will ensure things are imported by WiX at the appropriate time.

After this is configured the use of directory.build.props and directory.build.targets will be as expected. If WiX ever natively supports these build extensions, you'll be aligned and should be able to remove these explicit imports at your leisure.

like image 146
Chris Martinez Avatar answered Feb 02 '23 07:02

Chris Martinez