views:

442

answers:

2

I have created a task for MSBuild that is to be used by developers and would like to create an installer to install the task and the associated .targets file into the MSBuild extensions folder in Program Files (usually C:/Program Files/MSBuild on 32-bit XP).

To do this properly, I would like to ask the system for that folder location at installation time - is there a registry key that provides this information or some other installer property? I intend to use WiX for the installation.

+2  A: 

Wix itself has a MSBuild task so I think its best to see how they did it, the relvent source is Toolset.wxs (Google Code Search).

Look at the part where they defined the MSBuild Folder:

<DirectoryRef Id="ProgramFilesFolder">
    <Directory Id="Dir_MSBuild" Name="MSBuild">
        <Directory Id="Dir_MSBuildMS" Name="Microsoft">
            <Directory Id="Dir_MSBuildMSWix" Name="WiX">
                <Directory Id="Dir_MSBuildMSWix35" Name="v3.5">
                    <Component Id="WixMSBuildBinaries35" 
                              Guid="2CB1EA5F-2542-4AFF-A05B-FAF576265F89" 
                              Win64="no">
                        <File Source="WixTasks.dll" Checksum="yes" 
                              KeyPath="yes" Vital="yes" />
                    </Component>
                </Directory>
            </Directory>
        </Directory>
    </Directory>
</DirectoryRef>

This will install the Wix MsBuild task (WixTasks.dll) under \Program Files\MSBuild\Microsoft\Wix

Shay Erlichmen
If you're using 64 bit windows, it will install in the wrong folder. They must have some other code which handles Program Files or Program Files (x86).Actually I just dug through their code, it looks? like they include both x86 and x64 components, and just overwrite the x86 components with the x64 components if it's an x64 platform. Interesting :)
Si
+1  A: 

We do exactly this (and more:)

Create a wxi file with something like:

<!-- Product name as you want it to appear in Add/Remove Programs-->
<?if $(var.Platform) = x64 ?>
  <!-- Product name as you want it to appear in Add/Remove Programs-->
  <?define ProductName = "Custom MSBuild Tasks (64 bit)" ?>
  <?define Win64 = "yes" ?>
  <?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
<?else ?>
  <?define ProductName = "Custom MSBuild Tasks" ?>
  <?define Win64 = "no" ?>
  <?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
<?endif ?>

<!-- Directory name used under MSBuild -->
<?define InstallName = "CustomTasks" ?>

And then when you need to define your components:

<Fragment Id="ComponentsFragment">
  <Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="$(var.PlatformProgramFilesFolder)">
      <Directory Id="MSBuildFolder" Name="MSBuild">
        <Directory Id="INSTALLLOCATION" Name="$(var.InstallName)">
          ... Your custom .Targets and tasks go here
Si
Thanks. As I suspected, the MSBuild path is hard-coded into the installer. I like the code for switching between 64 and 32 bit. However, we currently don't have any 64-bit hardware to test on so I'm not sure I should even try to support it when I can't validate what I write.
Jeff Yates
Si