Search code examples
visual-studio-2010wixtfsbuildwix3.5

How do I stipulate WiX3.5 file source paths to work from non-referenced projects within my VS2010 solution


I've been looking for some considerable time for an answer to my question regarding using Team Build in conjunction with the WiX3.5 installer (which is fully installed on the Team Build Agent). In a nutshell my problem is similar to many of the forum questions but with a slight twist. In order to reference a component in our Wix Fragments, we use the pattern:

<Component Id="SomeAssembly.dll" Guid="80C99053-D78C-449C-9645-9031E50FD95F">
    <File Id="SomeAssembly.dll" Source="$(var.MyNamespace.TargetDir)\SomeAssembly.dll" KeyPath="yes"/>
  </Component>

Where the $(var.MyNamespace.TargetDir) variable is automatically supplied by the WiX build engine when you use a project reference within your WiX project. I have noted that it is only possible to use Project references within my solution which is where my problem begins.

In my team build definition I have a number of solutions that are being built as part of the build process (around about 30 so far) as these components can be used to make up a number of other products within the same source tree. When team build runs however, the relative paths to the component files changes to that of a flat (ish) file structure which in the above example is fine, however for assemblies that are referenced in a purely relative path fashion fail as the build process has moved the project output.

What is the best way to overcome this problem? Should I create one gigantic solution that contains every one of my projects in it and use project references throughout? Or is there a neater less work intensive way that I can resolve this?

Thank you for your time!


Solution

  • In the end I resorted to solving this problem by using a single "Path Variables" file which I subsequently included in all of my *.wxs files using the pre-processor directive.

    For projects that weren't directly referenced by a project reference within my WiX project I copied the same naming convention for the variables e.g.

    Namespace.ProjectName.TargetDir

    And used the DevEnvDir variable that is defined in the Visual Studio build within a set of pre-processor if and defines. The ugliness comes from the DevEnvDir variable when it hasn't been officially set by Team Build, but it gets set with the value "Undefined if not building from within Visual Studio" which I think is extremely unpleasant. This makes it hard to simply use an approach.

    My approach for the PathVariables.wxi file:

    <!-- Safety check for the variable -->
    <?ifndef DevEnvDir ?>
        <?define IsDesktopBuild = false ?>
    <?else?>
       <?if $(var.DevEnvDir) = "*Undefined if not building from within Visual Studio*" ?>
         <?define IsDesktopBuild = false ?>
       <?else?>
          <?define IsDesktopBuild = true ?>
       <?endif?>
    <?endif?>
    

    After which you need to set-up any of the additional as follows:

    <?if $(var.IsDesktopBuild)=false ?>
       <!--Build is TFS2010, default is to the OutDir variable -->
      <?define Namespace.Project.TargetDir = "$(var.OutDir)"?>
    <?else?>
      <!-- Build is Local Build -->
      <?define Namespace.Project.TargetDir = C:\LocalFolderPath\Bin\$(var.Configuration)"?>
    <?endif?>
    

    Then within any of your wxs files, ensuring you've included the:

    <?include [PathAsAppropriate]\PathVariables.wxi ?>
    

    You can then universally refer to the file path in the same fashion regardless of local build versus Team Build.

    <Component Id="Namespace.Project.dll" Guid="*">
        <File Id="Namespace.Project.Dll" Source="$(var.Namespace.Project.TargetDir)\Project.dll"/>
    </Component>