3
votes

I have a Visual Studio solution that we have been building with VS 2015 using the Visual Studio Online Build. We want to convert the build to VS 2017. It builds locally for me with no error. However, when building online using the "VS2017 Hosted" build agent it fails with the following error when trying to build my WIX based MSI:

DEV\Setup\UISetup\UISetup.wixproj(56,3): Error MSB4019: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\WiX\v3.x\Wix.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

Troubleshooting, the wixproj does have an import statement for this path:

$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets

I put some extra steps in the build and found the following as a comparison of the two build agents:

"Hosted" (build works on this VS 2015 build agent)

 wix.targets Is Here:     C:\Program Files (x86)\MSBuild\Microsoft\WiX\v3.x\wix.targets 

 With Diagnostic output on MSBuild, here are the MSBuild property settings
 2017-08-19T19:12:13.3864207Z MSBuildExtensionsPath   = C:\Program Files (x86)\MSBuild
 2017-08-19T19:12:13.3864207Z MSBuildExtensionsPath32 = C:\Program Files (x86)\MSBuild
 2017-08-19T19:12:13.3864207Z MSBuildExtensionsPath64 = C:\Program Files\MSBuild

Hosted VS2017 (same build fails on this build agent)

 Looking here for wix.targets:     C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\WiX\v3.x\Wix.targets <-- which errors

 But wix.targets is here:          C:\Program Files (x86)\MSBuild\Microsoft\WiX\v3.x\wix.targets <-- same as “Hosted” build agent

 With Diagnostic output on MSBuild, here are the MSBuild property settings
 2017-08-19T19:21:06.5320962Z MSBuildExtensionsPath   = C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild <-- Different on this build agent
 2017-08-19T19:21:06.5320962Z MSBuildExtensionsPath32 = C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild <-- Different on this build agent
 2017-08-19T19:21:06.5320962Z MSBuildExtensionsPath64 = C:\Program Files\MSBuild

I have opened a ticket with Microsoft support, but so far, they have been no help. The real issue is that MSBuildExtensionsPath32 is pointing to a different folder on the "VS2017 Hosted" build agent, but the wix.targets file is in the original folder. I would hate to hard code the path to wix.targets, but I really don't see an alternative.

Any ideas?

Thanks.

3
Have you considered integrating WiX into your project? There are also NuGet packages that do a similar thing and not require build agents to have WiX extensions installed. - Martin Ullrich
I may get to that point, but for right now, I would just like to fix the existing build. Thanks for the suggestion though... - Steve0212
after looking more at this, that is the best solution. Post it as an answer and I will mark it as correct. Thanks - Steve0212

3 Answers

3
votes

VS 2017 now use an isolated install where multiple version of VS (e.g. VS 2017 Community, Enterprise and VS 2017 preview versions) can be installed side-by-side and are no longer a machine-wide install.

This means that all extensions are required to install into the VS version itself, like the VS 2017 plugin for WiX does. This means that when building with the msbuild tooling of a VS 2017 install, it may not find globally installed tools like WiX if the extension has not been installed into that particular VS instance, which seems to be the case for the hosted VSTS agents.

To work around such problems, NuGet packages like this one (maintained at https://github.com/kzu/WiX) exists that contain the tools needed to build WiX projects so a nuget restore will fetch the required assets and the project will use those during the build and not require software to be installed on the build agent.

2
votes

The problem is that MSBuild v15 changed how MSBuildExtensionsPath32 works to support local, per-instance installation. When used directly in an Import, it continues to point to the global location. So your .wixproj needs to handle wix.targets differently than it used to, before MSBuild became per-instance. Take a look at a .wixproj that's created from Visual Studio with File|New Project; it looks like this at the bottom:

<Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)' != '' " />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets" Condition=" '$(WixTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets') " />
<Target Name="EnsureWixToolsetInstalled" Condition=" '$(WixTargetsImported)' != 'true' ">
  <Error Text="The WiX Toolset v3.11 (or newer) build tools must be installed to build this project. To download the WiX Toolset, see http://wixtoolset.org/releases/" />
</Target>
0
votes

We are using Azure DevOps 2019 on-prem and received the same error. In the Build Pipeline, we were using an MSBuild Task with MSBuild Version = MSBuild 16.0 to to build the solution (which included the WIX project).

We switched the MSBuild Version = MSBuild 14.0, and the error went away. It is a somewhat temporary fix until we require a more recent MSBuild verion, but is suffices for now.