directory.build.props and directory.build.targets is not working with Windows Installer Wix projects. *.wixproj
How to fix this issue?
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.
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))')" />
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With