51

I'm starting to use WiX in order to do automated builds to create msi's of my c# projects and am experiencing the error "Undefined preprocessor variable '$(var.MyProject.TargetDir)'"

I am using the latest WiX v3.0.5419. Inside my wxs file I am trying to use pre-processor variables that are listed on this webpage (http://blogs.msdn.com/jrock/archive/2008/01/29/complete-list-of-candle-preprocessor-variables.aspx)

<Component Id="MyId" Guid="MyGuid">
   <File Id="MyId" Name="MyName" KeyPath="yes" 
      Source="$(var.MyProject.TargetDir)\MyName.dll" />
</Component>

I have added the reference for MyProject to the .wixproj and if I open it up in Notepad I can see the reference.

<ItemGroup>
  <ProjectReference Include="..\MyProject.csproj">
    <Name>MyProject</Name>
    <Project>{guid}</Project>
    <Private>True</Private>
  </ProjectReference>
</ItemGroup>

This is my nant build script that I use to create the msi. Maybe it's because the .wixproj knows about the project reference which isn't used in the build?

<exec basedir="${tools.wix}" managed="true" program="candle.exe">
  <arg line='-out "${tools.wix.objfile}"' />
  <arg value="../MySetup.wxs" />
</exec>

Can anyone enlighten me on this please?

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
David
  • 15,150
  • 15
  • 61
  • 83

1 Answers1

56

As you already remarked, your nant build script is not using the wixproj file at all.

You are mixing two different ways to build a wix setup here:

  1. You can use the candle.exe and light.exe command line tools directly. This ignores the .wixproj file. This is what you are doing in your nant build script. To pass values for preprocessor variables like $(var.MyProject.TargetDir), use options like -dMyProject.TargetDir=c:\foo.

  2. You can author a .wixproj file with votive (the visual studio add-on for wix). Like all visual studio project files, a wixproj file is actually a msbuild file which can be build with msbuild.exe. Variables like $(var.MyProject.TargetDir) are automatically set by the msbuild tasks for building wix setups if the correct project reference exists.

I recommend you build the wixproj file with the <msbuild> nant task. This ensures that your nant build does the same as when you build the setup manually from visual studio.

Wim Coenen
  • 66,094
  • 13
  • 157
  • 251
  • Thanks very much. I just found out that the wixproj is a msbuild file and I was actually already building it correctly through building my solution! – David Jan 14 '10 at 14:15
  • 1
    Just as a quick heads up -- The correct way to specify the option would be -dMyProject.TargetDir. The leading var. is erroneous. http://geekswithblogs.net/Howard/archive/2009/01/20/wix-variables.aspx – Sean Anderson Dec 21 '11 at 00:22
  • Every time I use WIX I forget about how preprocessor variables have to be declared on the command line. Thanks man! – sky-dev Nov 20 '14 at 20:35
  • 2
    I was trying to build a simple installer to start working with WiX by following **[these](http://wixtoolset.org/documentation/manual/v3/votive/authoring_first_votive_project.html)** instructions. As a result, I am getting the "Undefined preproc var `$(var.MyApplication.TargetPath)`" error. I tried to add in the Build props `var.myApplication.TargetPath=D:\Apps;` but the error remained. Can you help? I am missing something in the answer ... the var seems to be correct (see **[this](https://blogs.msdn.microsoft.com/jrock/2008/01/29/complete-list-of-candle-preprocessor-variables/)** list). – Matt Dec 15 '16 at 10:02
  • 4
    @Matt You need to add reference to the project you are trying to install. – Eternal21 Oct 08 '18 at 18:36
  • 1
    "If the correct reference exists" Thank you very much. – Remi Beaulieu Apr 07 '19 at 02:38