Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using NuGet with WIX doesn't work when building release

I have a solution which contains a WIX project. I've added WIX via NuGet months ago, and it's version 3.8.1128.0 Everything works fine when I'm building during my development process.

When I'm ready to release, I branch the folder in SVN, and then pull the branch down to my development machine. When I open the solution in the branch, it can't open the WIX project. (It says "(load failed)" next to the project.

When I try to reload the project from VS, I get the error

The imported project "c:\Projects\xxxxx\yyyyy\SolutionName\packages\WiX.Toolset.3.8.1128.0\tools\wix\wwix.targets" was not found. Confirm that the path in the < Import > declaration is correct, and that the file exists on disk.

I've tried to add the Wix Toolset (unofficial) NuGet package, but I only see the 3.9.1208.0 version when I go to the "Online" tab of the Manage NuGet Packages for the solution.

The goal is to get the solution which includes projects for the binary and the wix msi package onto a build server, but if I can't rely on NuGet to install WiX, I'm not sure how to go about setting this up on another machine.

like image 423
bpeikes Avatar asked Apr 17 '15 20:04

bpeikes


1 Answers

Looking at the the WiX Toolset NuGet package it modifies the paths to the WiX MSBuild files so that the MSBuild files are used from the NuGet package instead of from C:\Program Files\WiX where they are when WiX is installed on the machine. The relevant parts of the project file are shown below:

  <PropertyGroup>
    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>    
  </PropertyGroup>

  <PropertyGroup>
    <WixToolPath>$(SolutionDir)packages\WiX.Toolset.3.8.1128.0\tools\wix\    </WixToolPath>
    <WixTargetsPath>$(WixToolPath)wix.targets</WixTargetsPath>
    <WixTasksPath>$(WixToolPath)WixTasks.dll</WixTasksPath>
  </PropertyGroup>
  <Import Project="$(WixTargetsPath)" />

Since this is a WiX project file the Import element does not have a condition that checks if the WiXTargetsPath exists so Visual Studio will fail to load the project if the Wix.targets file is missing. Unfortunately adding a condition, as shown below, whilst allowing Visual Studio to load the project does not fix the build.

  <Import Project="$(WixTargetsPath)" Condition="Exists($(WixTargetsPath))"/>

With the above condition in the project file then Visual Studio on building the project will restore the WiX NuGet package automatically, if you have a recent version of NuGet installed, but you still get a build error about a missing Build target for the WiX project. This build error can only be fixed by closing and re-opening the solution again after WiX NuGet package has been restored.

On the build server I would create a pre-build step that restores the NuGet packages using NuGet.exe restore before the WiX project is built:

NuGet.exe restore path\to\the\solution\yoursolution.sln

That will restore the WiX package. Then you can build the WiX project without any errors about missing WiX targets files.

Another way would be to check in the packages directory into source control. However that will add binaries to the source control which you may not want to do.

Also WiX.Toolset.3.8.1128.0 is available from nuget.org but the NuGet dialog will show you the latest version. You can install specific versions of NuGet packages using the Package Manager Console. When NuGet 3.0 is released you should be able to do the same thing from the NuGet dialog.

like image 69
Matt Ward Avatar answered Nov 25 '22 14:11

Matt Ward